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 '正文內(nèi)容
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 '如有屏蔽的詞語出現(xiàn),直接跳到下一個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
網(wǎng)頁名稱:天涯社區(qū)論壇貼子粗加工
文章源于:
http://weahome.cn/article/jgoeop.html