温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

天涯社区论坛贴子粗加工

发布时间:2020-06-02 15:05:25 来源:网络 阅读:373 作者:zmj9152 栏目:建站服务器
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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI