五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

抓取京東商品評論-以你的名字書籍為例

2023-02-07 21:15 作者:蕪湖小量化  | 我要投稿

# 分析網(wǎng)頁,獲得評論所在地址 響應(yīng)內(nèi)容類似一個json文件,可以進(jìn)行處理后得到j(luò)son格式


評論保存的地址

#? 所用的庫

import json
import requests

# 抓取并打印評論內(nèi)容

headers = {
? ?'accept': '*/*',
? ?'accept-encoding': 'gzip, deflate, br',
? ?'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
? ?'connection': 'keep-alive',
? ?'cookie': '?',
? ?'host': 'club.jd.com',
? ?'referer': 'https://item.jd.com/',
? ?'user-agent': ''
}


page_num = 0? ? # 評論頁碼
serial_num = 0? ?# 評論序列號
while page_num < 6:? # 抓取前6頁
? ?url = 'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=10699613518&score=0&sortType=5&page={}&pageSize=10&isShadowSku=0&fold=1'.format(page_num)
? ?page_num += 1
? ?html = requests.get(url, headers=headers)
? ?text = str(html.content, encoding='iso-8859-1')
? ?json_str = text.replace('fetchJSON_comment98(', '')? ? # 去頭
? ?json_str_2 = json_str.replace(')', '')? ? # 去尾
? ?json_str_3 = json_str_2.replace(';', '')
? ?json_obj = json.loads(json_str_3)

? ?for i in range(0, len(json_obj['comments'])):
? ? ? ?try:
? ? ? ? ? ?comment = json_obj['comments'][i]['content'].encode(encoding='iso-8859-1').decode('GB18030')


? ? ? ? ? ?if comment != '此用戶未填寫評價內(nèi)容':
? ? ? ? ? ? ? ?print(serial_num + 1, '. ? ?', comment)
? ? ? ? ? ? ? ?creation_time = json_obj['comments'][i]['creationTime']
? ? ? ? ? ? ? ?nickname = json_obj['comments'][i]['nickname'].encode(encoding='iso-8859-1').decode('GB18030')
? ? ? ? ? ? ? ?print(creation_time)
? ? ? ? ? ? ? ?print(nickname)
? ? ? ? ? ? ? ?print('----------------')
? ? ? ? ? ? ? ?serial_num += 1

? ? ? ?except Exception as e:
? ? ? ? ? ?print(e)

私貨:沒有

打印輸出預(yù)覽


抓取京東商品評論-以你的名字書籍為例的評論 (共 條)

分享到微博請遵守國家法律
汉阴县| 鄂州市| 彰化县| 游戏| 富民县| 乐亭县| 安岳县| 盖州市| 沙坪坝区| 乌兰浩特市| 东乌| 江城| 乌兰浩特市| 兴仁县| 乳源| 富源县| 万荣县| 青州市| 江油市| 巴中市| 卢湾区| 清镇市| 阜宁县| 黑河市| 承德县| 甘谷县| 那曲县| 万年县| 仙居县| 青铜峡市| 斗六市| 凤阳县| 鸡东县| 高阳县| 汉阴县| 喀什市| 旌德县| 弥渡县| 绥德县| 肇东市| 长岭县|