DataTables("头条文章").DataRows.Clear
Dim web As new System.Windows.Forms.WebBrowser
web.Navigate("http://toutiao.com/m6192786832/")
Do Until web.ReadyState = 4
Application.DoEvents
Loop
Do Until web.DocumentText.contains("没有更多啦")
web.Document.Window.ScrollTo(0, 0)
web.Document.Window.ScrollTo(0, web.Document.Body.ScrollRectangle.Height)
Application.DoEvents
Loop
Dim lis = web.Document.GetElementById("content-left").GetElementsByTagName("li")
Dim str As String = ""
For i As Integer = 0 To lis.count-1
Dim lsa = lis(i).GetElementsByTagName("a")
For Each a As object In lsa
Dim dr As DataRow = DataTables("头条文章").AddNew()
If a.GetAttribute("className") = "title-box link" Then
str &= a.InnerHtml & vbcrlf
str &= a.GetAttribute("href") & vbcrlf
dr("网址") = a.GetAttribute("href")
Dim bt As System.Windows.Forms.HtmlElement
bt = web.Document.GetElementByID("keywords") '今日头条单位标题
dr("单位") = bt.innerText & " " & bt.GetAttribute("content")
dr("文章标题") = a.InnerHtml
Else
If a.GetAttribute("className") = "y-left" Then
Dim lsspan = lis(i).GetElementsByTagName("span")
If lsspan(0).InnerHtml.contains("阅读") Then
str &= lsspan(0).InnerHtml & " " & lsspan(1).InnerHtml & " " & lsspan(2).InnerHtml & vbcrlf & vbcrlf
Dim 阅读数 As String = lsspan(0).InnerHtml
Dim Parts() As String = 阅读数.Split("阅读")
dr("阅读数") = Parts(0)
Dim 评论数 As String = lsspan(1).InnerHtml
Dim Parts1() As String = 评论数.Split("评论")
dr("评论数") = Parts1(0)
dr("发布时间") = lsspan(2).InnerHtml '
Else
If lsspan(0).InnerHtml.contains("播放") Then
str &= lsspan(0).InnerHtml & " " & lsspan(1).InnerHtml & " " & lsspan(2).InnerHtml & vbcrlf & vbcrlf
Dim 阅读数 As String = lsspan(0).InnerHtml
Dim Parts2() As String = 阅读数.Split("播放")
dr("阅读数") = Parts2(0)
output.Show(Parts2(0))
Dim 评论数 As String = lsspan(1).InnerHtml
Dim Parts1() As String = 评论数.Split("评论")'
dr("评论数") = Parts1(0)
dr("发布时间") = lsspan(2).InnerHtml
End If
End If
End If
End If
Next
Next
output.Show(str)
运行效果2:
此主题相关图片如下:0.png

运行代码2:
DataTables("头条文章").DataRows.Clear
Dim web As new System.Windows.Forms.WebBrowser
web.Navigate("http://toutiao.com/m6192786832/")
Do Until web.ReadyState = 4
Application.DoEvents
Loop
Do Until web.DocumentText.contains("没有更多啦")
web.Document.Window.ScrollTo(0, 0)
web.Document.Window.ScrollTo(0, web.Document.Body.ScrollRectangle.Height)
Application.DoEvents
Loop
Dim lis = web.Document.GetElementById("content-left").GetElementsByTagName("li")
Dim str As String = ""
For i As Integer = 0 To lis.count-1
Dim lsa = lis(i).GetElementsByTagName("a")
For Each a As object In lsa
If a.GetAttribute("className") = "title-box link" Then
Dim dr As DataRow = DataTables("头条文章").AddNew()
str &= a.InnerHtml & vbcrlf
str &= a.GetAttribute("href") & vbcrlf
If a.GetAttribute("className") = "y-left" Then
Dim lsspan = lis(i).GetElementsByTagName("span")
If lsspan(0).InnerHtml.contains("阅读") Then
str &= lsspan(0).InnerHtml & " " & lsspan(1).InnerHtml & " " & lsspan(2).InnerHtml & vbcrlf & vbcrlf
Dim 阅读数 As String = lsspan(0).InnerHtml
Dim Parts() As String = 阅读数.Split("阅读")
dr("阅读数") = Parts(0)
MessageBox.Show(Parts(0))
Dim 评论数 As String = lsspan(1).InnerHtml
Dim Parts1() As String = 评论数.Split("评论")
Dim bt As System.Windows.Forms.HtmlElement
bt = web.Document.GetElementByID("keywords") '今日头条单位标题
dr("单位") = bt.innerText & " " & bt.GetAttribute("content")
dr("文章标题") = a.InnerHtml
dr("发布时间") = lsspan(2).InnerHtml
dr("评论数") = Parts1(0) '
dr("网址") = a.GetAttribute("href")
Else
If lsspan(0).InnerHtml.contains("播放") Then
str &= lsspan(0).InnerHtml & " " & lsspan(1).InnerHtml & " " & lsspan(2).InnerHtml & vbcrlf & vbcrlf
Dim 阅读数 As String = lsspan(0).InnerHtml
Dim Parts2() As String = 阅读数.Split("播放")
dr("阅读数") = Parts2(0)
MessageBox.Show(Parts2(0))
Dim 评论数 As String = lsspan(1).InnerHtml
Dim Parts1() As String = 评论数.Split("评论")
Dim bt As System.Windows.Forms.HtmlElement
bt = web.Document.GetElementByID("keywords") '今日头条单位标题
'Output.Show(bt.innerText & " " & bt.GetAttribute("content"))
dr("单位") = bt.innerText & " " & bt.GetAttribute("content")
'msgbox(bt.innerText & " " & bt.GetAttribute("content"))
dr("文章标题") = a.InnerHtml
dr("发布时间") = lsspan(2).InnerHtml
dr("评论数") = Parts1(0)
'Dim lsa1 = lis(i).GetElementsByTagName("p")
'For Each p As object In lsa1
'If p.GetAttribute("className") = "abstract" Then
'dr("正文") = p.InnerHtml
'End If
'Next
'
dr("网址") = a.GetAttribute("href")
End If
End If
End If
End If
Next
Next
output.Show(str)