千家信息网

天涯社区论坛贴子粗加工

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,VBA 从天涯论坛的帖子中提取正文Sub 天涯贴子简单抓取() Dim cnt As Integer arr = Array("评论", "举报", "楼主", "作者", "草稿", "热贴",
千家信息网最后更新 2024年09月22日天涯社区论坛贴子粗加工
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 = NothingEnd Sub


0