python3爬蟲 -----新浪微博(m)-------評論爬取


 1 import requests
 2 import time
 3 import re
 4 
 5 
 6 
 7 p=0
 8 while p<=0:
 9     p+=1
10     url = "https://m.weibo.cn/api/comments/show?id=4257289713596342&page="+str(p) #楊洋為例
11     html = requests.get(url)
12     print(html)
13     try:
14         for c in range(len(html.json()['data']['data'])):
15             data=html.json()['data']['data'][c]['text']
16             with open('comments.txt','a',encoding='utf-8') as f:
17                 comments=''.join(re.findall('[\u4e00-\u9fa5]',data))
18                 print(comments)
19                 f.write(comments+'\n'*2)
20     except:
21         None

 

 

效果如下所示:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM