资源简介
这些代码是基于python开发,旨在实现用python爬取微博评论。
代码片段和文件信息
import requests
base_url=‘https://m.weibo.cn/api/comments/show?id=4161120933574581&page={page}‘
cookies={‘Cookie‘:‘_T_WM=316b107bb9a2cf402722c2f22f594a4c; SUB=_2A2501dvvDeRhGeVH4lcZ8S7KyzyIHXVUOeWnrDV6PUJbkdANLWXHkW015u1rrU45Mt5u451INMWTJj7x7w..; SUHB=0OMUG0U6KApMmK; SCF=AgIFMg6DnS1WQtUIvA2jSyIQqhKvDBX1DnFqL5Z7XWZ-KfWqVBxUelMG2PXrwSzUviTBJmCNnQNKZ7L9Uvi65HI.; H5:PWA:UID=1; M_WEIBOCN_PARAMS=oid%3D4161120933574581%26featurecode%3D20000320%26luicode%3D10000011%26lfid%3D100103type%253D1%2526q%253D%25E5%2588%259B%25E6%2596%25B0%25E6%2594%25BF%25E7%25AD%2596%26uicode%3D20000061%26fid%3D4161120933574581‘}
headers={‘User-Agent‘:‘Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML like Gecko) Chrome/60.0.3112.113 Mobile Safari/537.36‘}
for i in range(116):
try:
url=base_url.format(page=i)
resp=requests.get(urlheaders=headerscookies=cookies)
jsondata=resp.json()
data=jsondata.get(‘data‘)
for d in data:
comment=d.get(‘text‘)
print(comment)
except:
print(‘*‘*10)
pass
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1115 2017-10-13 15:24 weibopinlun.py
----------- --------- ---------- ----- ----
1115 1
评论
共有 条评论