以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求助:网页源码获取之后,不知道是不是遍历循环不对,居然只有一条数据,实际有77条数据,麻烦补充下循环遍历,谢谢! (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=92413) |
-- 作者:李孝春 -- 发布时间:2016/11/2 20:44:00 -- 求助:网页源码获取之后,不知道是不是遍历循环不对,居然只有一条数据,实际有77条数据,麻烦补充下循环遍历,谢谢! 代码如下: Dim web As new System.Windows.Forms.WebBrowser web.ScriptErrorsSuppressed = True web.Navigate("http://search.jcrb.com/was5/web/search?page=1&channelid=263328&perpage=10000000&outlinepage=10000000") Do Until web.ReadyState = 4 AndAlso web.document.GetElementsByTagName("table").count > 1 Application.DoEvents Loop Dim str As String = "" Dim tb1s = web.document.GetElementsByTagName("table")(4) \'从第4个<Table>开始查找 For Each tb1 As object In tb1s.GetElementsByTagName("tr")\'遍历TR\' Dim sa = tb1.GetElementsByTagName("a")\'获取A标签元素\' If sa.count > 0 Then Dim a = sa(0) Dim Tel As String = a.InnerHtml Dim Parts1() As String = Tel.Split("</FONT>") str &= Parts1(0) & vbcrlf str &= a.GetAttribute("href") & vbcrlf Dim shijian As String= (FileSys.GetName(a.GetAttribute("href")).Insert(5,"-")).Insert(8,"-") Dim Parts() As String = shijian.Split("_") str & =Parts(0).Remove(0,1) & vbcrlf End If Next output.Show(str) 文章列表源码: <Table width="980" align="center" border="0" cellpadding="0" cellspacing="5"> <tr> <td class=f> <font size="3"><a href="http://www.gzwengan.jcy.gov.cn/jcyw/201605/t20160505_1787530.shtml" target="_blank">加强与代表面对面沟通,进一步提高代表的满意率</font> </a> <br><font size=-1><font color=#008000>2016.05.05 作者:</font> <br> <br> 4月27日,瓮安县人民检察院陈德清副检察长和人大代表联络办公室的两名工作人员专程到中坪镇政府向第十六届人大代表?中坪镇人大主席王成伦汇报提案办理情况 <br></font> </td> </tr> </Table> [此贴子已经被作者于2016/11/2 20:53:15编辑过]
|
-- 作者:有点蓝 -- 发布时间:2016/11/2 21:03:00 -- 导出分析一下就知道了,table都在同一个层次,并不是在第4个table里面 Dim web As new System.Windows.Forms.WebBrowser web.ScriptErrorsSuppressed = True web.Navigate("http://search.jcrb.com/was5/web/search?page=1&channelid=263328&perpage=10000000&outlinepage=10000000") Do Until web.ReadyState = 4 AndAlso web.document.GetElementsByTagName("table").count > 1 Application.DoEvents Loop output.Show(web.document.body.Innerhtml) |
-- 作者:李孝春 -- 发布时间:2016/11/2 21:43:00 -- 回复:(有点蓝)导出分析一下就知道了,table都在同一... 我分析了前三个table里面的数据我不想要,所以从第四个之后开始读取。 折腾了半天 怎么弄都只有一条数据 弄上下面代码,运行直接没有反映了【去掉红色部分又能进行读取数据,但是还是只有一条数据】 Dim web As new System.Windows.Forms.WebBrowser web.ScriptErrorsSuppressed = True web.Navigate("http://search.jcrb.com/was5/web/search?page=1&channelid=263328&perpage=10000000&outlinepage=10000000") Do Until web.ReadyState = 4 AndAlso web.document.GetElementsByTagName("table").count > 1 Application.DoEvents Loop \'output.Show(web.document.body.Innerhtml) Dim str As String = "" Dim tb1s = web.document.GetElementsByTagName("table")(4) \'从第4个<Table>开始查找 For Each tb1 As object In tb1s.GetElementsByTagName("td")\'遍历Td\' Dim sa = tb1.GetElementsByTagName("a")\'获取A标签元素\' For Each a As object In sa If a.GetAttribute("className") = "f" Then If sa.count > 0 Then Dim a1 = sa(0) Dim Tel As String = a.InnerHtml Dim Parts1() As String = Tel.Split("</FONT>") str &= Parts1(0) & vbcrlf str &= a1.GetAttribute("href") & vbcrlf Dim shijian As String= (FileSys.GetName(a.GetAttribute("href")).Insert(5,"-")).Insert(8,"-") Dim Parts() As String = shijian.Split("_") str & =Parts(0).Remove(0,1) & vbcrlf End If End If Next Next output.Show(str) |
-- 作者:有点蓝 -- 发布时间:2016/11/2 22:02:00 -- 代码始终在第四个table里面找,怎么会有呢,一个table只有一条数据 |
-- 作者:有点蓝 -- 发布时间:2016/11/2 22:02:00 -- Dim web As new System.Windows.Forms.WebBrowser web.ScriptErrorsSuppressed = True web.Navigate("http://search.jcrb.com/was5/web/search?page=1&channelid=263328&perpage=10000000&outlinepage=10000000") Do Until web.ReadyState = 4 AndAlso web.document.GetElementsByTagName("table").count > 1 Application.DoEvents Loop Dim str As String = "" Dim tb1s = web.document.GetElementsByTagName("table") \'从第4个<Table>开始查找 For i As Integer = 4 To tb1s.count - 1 Dim tb1 = tb1s(i) Dim sa = tb1.GetElementsByTagName("a")\'获取A标签元素\' If sa.count > 0 Then Dim a = sa(0) Dim Tel As String = a.InnerHtml Dim Parts1() As String = Tel.Split("</FONT>") str &= Parts1(0) & vbcrlf str &= a.GetAttribute("href") & vbcrlf Dim shijian As String= (FileSys.GetName(a.GetAttribute("href")).Insert(5,"-")).Insert(8,"-") Dim Parts() As String = shijian.Split("_") str & =Parts(0).Remove(0,1) & vbcrlf End If Next output.Show(str)
|