この Web ページからテキストを取得する必要があります。プログラムの取引フィードを使用して、市場のセンチメントを分析したいと考えています。
ブラウザ コントロールと get element コマンドを使用しましたが、機能しません。問題は、ブラウザがページを開き始めるたびに、Java スクリプト エラーが発生することです。
私はDOMを試しましたが、私が何をする必要があるのか よく理解していないようです:)これがコードです:
Dim code As String
Using client As New WebClient
code = client.DownloadString("http://openbook.etoro.com/ahanit/#/profile/Trades/")
End Using
Dim htmlDocument As IHTMLDocument2 = New HTMLDocument(code)
htmlDocument.write(htmlDocument)
Dim allElements As IHTMLElementCollection = htmlDocument.body.all
Dim allid As IHTMLElementCollection = allElements.tags("id")
Dim element As IHTMLElement
For Each element In allid
element.title = element.innerText
MsgBox(element.innerText)
Next
更新:コメントで提案されているように、HTMLアジリティパックを試しましたが、このコードで再び立ち往生しています
Dim plain As String = String.Empty
Dim htmldoc As New HtmlAgilityPack.HtmlDocument
htmldoc.LoadHtml("http://openbook.etoro.com/ahanit/#/profile/Trades/")
Dim goodnods As HtmlAgilityPack.HtmlNodeCollection = htmldoc.DocumentNode.SelectNodes("THE PROBLEM")
For Each node In goodnods
TextBox1.Text = htmldoc.DocumentNode.InnerText
Next
今何をすべきかアドバイスはありますか?
OK、ソースコードだけのWebページをロードすると、必要なdivが非表示になり、ロードされないという問題がどういうわけかわかっていると思います。誰かがすべての隠しdivをロードする方法を知っていますか??
これが私の新しいコードです
Dim doc As New HtmlAgilityPack.HtmlDocument
Dim web As New HtmlWeb
doc = web.Load("http://openbook.etoro.com/ahanit/#/profile/Trades/")
Dim nodes As HtmlNode = doc.GetElementbyId("feed-items")
Dim id As String = nodes.WriteTo()
TextBox1.Text = TextBox1.Text & vbCrLf & id