Foxtable(狐表)用户栏目专家坐堂 → [求助]网页取值(又有新问题,见8楼)


  共有2879人关注过本帖树形打印复制链接

主题:[求助]网页取值(又有新问题,见8楼)

帅哥,在线噢!
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107757 积分:548124 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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)

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107757 积分:548124 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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)

 回到顶部
帅哥,在线噢!
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107757 积分:548124 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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

 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107757 积分:548124 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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()

 回到顶部
帅哥,在线噢!
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107757 积分:548124 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/19 14:01:00 [显示全部帖子]

调试技巧:http://www.foxtable.com/webhelp/scr/1485.htm

查询到的所有网页标签都判断一下,比如:
Dim tb1 As object = web.Document.GetElementsByTagName("table")(3) 这种如果网页没有第4个table,肯定就出错,判断一下
If tb1.count > 3

 回到顶部
帅哥,在线噢!
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107757 积分:548124 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/20 14:29:00 [显示全部帖子]

        Dim tb1 As object = web.Document.GetElementsByTagName("table")
        If tb1.count <= 3
            MessageBox.Show("出错1")
        End If

 回到顶部