VBA 从天涯论坛的帖子中提取正文
Sub 天涯贴子简单抓取()
Dim cnt As Integer
arr = Array("评论", "举报", "楼主", "作者", "草稿", "热贴", "论坛", "注册", "广告", "推荐") '屏蔽词汇
For y = 1 To 2
Set ie = CreateObject("internetexplorer.application")
With ie
.Navigate "http://bbs.tianya.cn/post-free-5758447-" & y & ".shtml" '5758447-1.shtml ,5758447-2.shtml等
' .Visible = True
Do Until ie.ReadyState = 4
DoEvents
Loop
For x = 0 To .Document.All.tags("div").Length - 1 '正文是在div中,div集合长度
ss = .Document.All.tags("div")(x).innertext '正文内容
len_ss = Len(ss) '正文长度
If len_ss < 100 Then '正文长度太短,直接跳到下一个div
GoTo 100
Else
For Each keys In arr
If InStr(ss, keys) > 0 Then GoTo 100 '如有屏蔽的词语出现,直接跳到下一个div
Next
cnt = cnt + 1
Debug.Print cnt & ":" & .Document.All.tags("div")(x).innertext '输出合乎要求的div
End If
100
Next x
End With
Next y
ie.Quit
Set ie = Nothing
End Sub
新闻名称:天涯社区论坛贴子粗加工
转载来源:
http://bzwzjz.com/article/jgoeop.html