以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]网页取值(又有新问题,见8楼) (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=147497) |
||||
-- 作者:yyzlxc -- 发布时间:2020/3/18 10:32:00 -- [求助]网页取值(又有新问题,见8楼) Dim web As New System.Windows.Forms.WebBrowser() web.ScriptErrorsSuppressed = True web.Navigate("https://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpOtherInfo/stockid/000002/menu_num/2.phtml") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim tb As object = web.Document.GetElementsByTagName("table")(4) Dim trs = tb.GetElementsByTagName("tr") For i As Integer = 0 To trs.count-1 Dim tds As object = trs(i).GetElementsByTagName("td") For j As Integer = 0 To tds.count-1 output.show(i & "行" & j & "列:" & tds(j).innerText) Next Next 如何将0列的第2行至最后行的数据读成一个用 “,” 号分隔的字符串,请各位老师指教,谢谢! [此贴子已经被作者于2020/3/19 10:16:14编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/18 10:38:00 -- dim s as string = "" For j As Integer = 1 To tds.count-1 s = s & "," & tds(j).innerText output.show(i & "行" & j & "列:" & tds(j).innerText) Next output.show(s)
|
||||
-- 作者:yyzlxc -- 发布时间:2020/3/18 10:52:00 -- 谢谢有点蓝老师的指教,如果只需要0列第二行及以后的字符串(1列的数据不需要),代码如何写?还请老师指教,谢谢!! |
||||
-- 作者:有点蓝 -- 发布时间:2020/3/18 11:01:00 -- dim s as string = "" For i As Integer = 1 To trs.count-1 Dim tds As object = trs(i).GetElementsByTagName("td") s = s & "," & tds(0).innerText Next output.show(s)
|
||||
-- 作者:yyzlxc -- 发布时间:2020/3/18 11:18:00 -- 代码出错 代码如下,错在哪里? Dim web As New System.Windows.Forms.WebBrowser() web.ScriptErrorsSuppressed = True web.Navigate("https://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpOtherInfo/stockid/000002/menu_num/2.phtml") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim tb As object = web.Document.GetElementsByTagName("table")(4) Dim trs = tb.GetElementsByTagName("tr") Dim s As String = "" For i As Integer = 1 To trs.count-1 Dim tds As object = trs(i).GetElementsByTagName("td") s = s & "," & tds(0).innerText Next output.show(s) |
||||
-- 作者:有点蓝 -- 发布时间:2020/3/18 11:22:00 -- For i As Integer = 1 To trs.count-1 Dim tds As object = trs(i).GetElementsByTagName("td") if tds.count> 0 s = s & "," & tds(0).innerText end if Next
|
||||
-- 作者:yyzlxc -- 发布时间:2020/3/18 11:34:00 -- 谢谢有点蓝老师,问题解决!! |
||||
-- 作者:yyzlxc -- 发布时间:2020/3/19 9:29:00 -- 又有新问题,代码运行50行左右,跳出运行错误对话框“超出系统资源”,并退出程序,如何解决,请老师指教,谢谢!!
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/19 10:23:00 -- 内存溢出。不要在循环里不断new浏览器实例 Dim web As New System.Windows.Forms.WebBrowser() web.ScriptErrorsSuppressed = True For Each dr As DataRow In DataTables("表A").Select("","简码") If dr.IsNull("简码") = False And dr.IsNull("行业") Then web.Navigate("https://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpOtherInfo/stockid/" & dr("简码") & "/menu_num/2.phtml") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim hy As String = "" Dim tb1 As object = web.Document.GetElementsByTagName("table")(3) Dim trs1 = tb1.GetElementsByTagName("tr") Dim tds1 As object = trs1(2).GetElementsByTagName("td") hy = tds1(0).innerText If hy = "" Then hy = "无" End If Dim gn As String = "" Dim tb2 As object = web.Document.GetElementsByTagName("table")(4) Dim trs2 = tb2.GetElementsByTagName("tr") For i2 As Integer = 1 To trs2.count-1 Dim tds2 As object = trs2(i2).GetElementsByTagName("td") If tds2.count > 0 If gn = "" Then gn = tds2(0).innerText Else gn = gn & "," & tds2(0).innerText End If End If Next If gn = "对不起,暂时没有相关概念板块信息" Then gn = "无" End If dr("行业") = hy dr("概念") = gn GC.Collect() End If Next DataTables("表A").Save() |
||||
-- 作者:yyzlxc -- 发布时间:2020/3/19 13:16:00 -- 谢谢有点蓝老师的指教,代码修改后,“超出系统资源”的问题得到解决,但是代码运行1000行左右会出现错误提示(如下),程序不会自己退出。 重新打开程序又可以运行,但是运行1000行左右,又会出现同样的错误,如何解决,还请有点蓝老师指教,谢谢!!
.NET Framework 版本:4.0.30319.42000 Foxtable 版本:2020.1.19.19 错误所在事件:窗口,窗口1,Button1,Click 详细错误信息: “3”的值对于“index”无效。“index”应介于 0 和 -1 之间。 参数名: index [此贴子已经被作者于2020/3/19 13:16:38编辑过]
|