xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

給定微博id和爬取評論數(shù)量,爬取對應(yīng)微博的評論,便于下一步的分詞和詞頻統(tǒng)計

資源截圖

代碼片段和文件信息

#?這里是完整代碼!!!!!!
#?完整爬取微博評論程序,只需要修改微博id即可
import?requests
import?json
import?re
#爬取微博評論寫入weibo_comment.txt
def?get_comment(weibo_id?url?headers?number):
????count?=?0
????fp?=?open(“weibo_comment_“+str(weibo_id)+“.txt“?“a“?encoding=“utf8“)
????#判斷爬取數(shù)目是否足夠
????while?count????????#判斷是否是第一組,第一組不加max_id
????????if?count?==?0:
????????????print(‘是第一組‘)
????????????try:
????????????????url?=?url?+?weibo_id?+?‘&mid=‘?+?weibo_id?+‘&max_id_type=0‘
????????????????web_data?=?requests.get(url?headers?=?headers)
????????????????js_con?=?web_data.json()
????????????????#獲取連接下一頁評論的max_id
????????????????max_id?=?js_con[‘data‘][‘max_id‘]
????????????????print(max_id)
????????????????comments_list?=?js_con[‘data‘][‘data‘]
????????????????for?commment_item?in?comments_list:
????????????????????comment?=?commment_item[“text“]
????????????????????#刪除表情符號
????????????????????label_filter?=?re.compile(r‘]*>‘?re.S)
????????????????????comment?=?re.sub(label_filter?‘‘?comment)
????????????????????fp.write(comment)
????????????????????count?+=?1
????????????????????print(“已獲取“+str(count)+“條評論。“)
????????????except?Exception?as?e:
????????????????print(str(count)?+?“遇到異常“)
????????????????continue
???????

評論

共有 條評論