我需要從this web page得到一些文字。我想用我的計劃中的交易飼料來分析市場情緒。來自網頁的文字
我用瀏覽器控件和get元素命令,但它不工作。問題是,無論何時我的瀏覽器開始打開頁面,我都會收到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
任何意見什麼現在?
好吧我想我知道問題是什麼,我需要的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
你試過HTML敏捷ACK:http://htmlagilitypack.codeplex.com/ – Shoban 2012-04-16 15:30:01
謝謝Shoban,但什麼也沒有,我知道:)我沒有太多EXP用vb所有上面的代碼是3天谷歌搜索的結果,仍然知道在視線內:) – user1336635 2012-04-16 16:07:20
shoban如果你現在如何工作plzz一些建議:) – user1336635 2012-04-17 10:22:52