国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ù)覽


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

分享到微博請遵守國家法律
汪清县| 桐柏县| 山东| 乌审旗| 灵川县| 洪江市| 新竹市| 平罗县| 堆龙德庆县| 拜泉县| 遂溪县| 铅山县| 柳州市| 黎川县| 乃东县| 怀化市| 乌苏市| 封丘县| 铁力市| 天台县| 密山市| 嘉禾县| 奉贤区| 灌南县| 西丰县| 玉龙| 茶陵县| 辉南县| 保山市| 兰溪市| 延寿县| 永康市| 红桥区| 宜阳县| 共和县| 满洲里市| 仁化县| 布尔津县| 漠河县| 翼城县| 兰考县|