以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]在网页上抓取表格上的数据,在命令窗口试运行起来有几个错误提示!----已解决,三楼! (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=96953) |
-- 作者:crychen -- 发布时间:2017/3/2 22:38:00 -- [求助]在网页上抓取表格上的数据,在命令窗口试运行起来有几个错误提示!----已解决,三楼! 本人编程小白,看文档自学中,想做一个小软件,在网页上抓取表格上的数据,在命令窗口试运行起来有几个错误提示,但是按“是”继续到最后能得到我想要的结果,其中有什么问题,请大神指点!! 1/ 代码 以下内容为程序代码: 1 Dim web As New System.Windows.Forms.WebBrowser() 2 web.Navigate("http://www.cambioschaco.com.py") 3 Do Until web.ReadyState = 4 4 Application.DoEvents 5 Loop 6 7 Dim tds As object = web.Document.GetElementById("exchange-usd").GetElementsByTagName("td") 8 9 For Each td As object In tds 10 Dim tdText As String = td.Innertext 11 Output.show(tdText) 12 Next 2/网页源码,网页上我要抓取的数据是不定时更新的。 以下内容为程序代码: 1<tr id="exchange-usd"> 2 3 <td><a href="http://www.cambioschaco.com.py/perfil-de-moneda/?currency=usd" data-toggle="tooltip" title="Ver Conversor e Histórico"><i class="moneda dolarUs"></i> Dólar Americano</a></td> 4 5 <td class="text-right"> <span class="purchase">5.380</span> <i class="pTrend estado suba"></i></td> 6 7 <td class="text-right"> <span class="sale">5.490</span> <i class="sTrend estado baja"></i></td> 8 9</tr> 3/ 错误提示截图链接(不会怎么发图,插入图片预览提示有错误)
[此贴子已经被作者于2017/3/4 19:29:05编辑过]
|
-- 作者:有点色 -- 发布时间:2017/3/3 1:11:00 -- 上传图片看这里
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=78
你可以屏蔽js错误的
web.ScriptErrorsSuppressed = True web.Navigate("http://www.cambioschaco.com.py") |
-- 作者:crychen -- 发布时间:2017/3/4 19:15:00 -- 谢谢!!已经解决! 得到了想要的数据并存入表,数据保存到表格部分的代码参考自本论坛的前靠先进之手!感谢! 以下内容为程序代码: 1 Dim Cols() As String = {"date","moneda","compra","venta"} 2 3 Dim web As New System.Windows.Forms.WebBrowser() 4 5 web.ScriptErrorsSuppressed = True 6 7 web.Navigate("http://www.cambioschaco.com.py") 8 9 Do Until web.ReadyState = 4 AndAlso web.Document.GetElementByid("main-exchange-content").InnerText > "" 10 Application.DoEvents 11 Loop 12 13 Dim tb As object = web.Document.GetElementById("main-exchange-content") 14 Dim trs As object = tb.GetElementsByTagName("tr") 15 Dim i As Integer = 1 16 17 For Each tr As object In trs 18 Dim tds As object = tr.GetElementsByTagName("td") 19 Dim time As object = web.Document.GetElementById("update-ts") 20 Tables("cambios").AddNew 21 22 If i <= 3 Then 23 For Each td As object In tds 24 Tables("cambios").Current("date") = time.Innertext 25 Tables("cambios").Current(Cols(i)) = td.Innertext 26 i = i + 1 27 Next 28 ElseIf i > 3 Then 29 i = i - 3 30 For Each td As object In tds 31 Tables("cambios").Current("date") = time.Innertext 32 Tables("cambios").Current(Cols(i)) = td.Innertext 33 i = i + 1 34 Next 35 End If 36 37 Next 38 39 DataTables("cambios").Save 40 下一步,将date列的字符型数据转换成日期型:03 MAR 2017 13:54 。
|