代码拉取完成,页面将自动刷新
同步操作将从 骨子里的偏爱/淘宝-1688-京东爬取 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import csv
import json
import tkinter
import sys
from tkinter import filedialog
import time
def open_file_dialog(title='请打开HAR文件'):
filePath = tkinter.filedialog.askopenfilename(title=title)
if filePath == '':
print('错误您没有打开任何har文件')
sys.exit()
return filePath
har = open_file_dialog()
har_file = open(har, 'r', encoding='utf-8')
har_file = har_file.read()
har_json = json.loads(har_file)
j_ahead = har_json['log']['entries']
nums = 0
csv_file = open(f'PDD-{time.strftime("%Y-%m-%d_%H-%M", time.localtime())}.csv', 'a', encoding='utf-8-sig', newline='')
csv_writer = csv.DictWriter(csv_file,
fieldnames=['goods_id', 'goods_name', 'goods_pic', 'mall_id', 'price', 'has_saled'])
csv_writer.writerow({'goods_id': '商品ID', 'goods_name': '商品名', 'goods_pic': '商品图片', 'mall_id': '店铺ID', 'price': '价格',
'has_saled': '参考销售量'})
csv_file.flush()
def read_json(Reqtext):
json_data = json.loads(Reqtext)
json_data = json_data['items']
for good in json_data:
info = good['item_data']['goods_model']
try:
ss = info['sales']
except:
try:
ss = info['sales_tip']
except:
ss = '未知'
csv_writer.writerow(
{'goods_id': info['goods_id'], 'goods_name': info['goods_name'], 'goods_pic': info['hd_thumb_url'],
'mall_id': info['mall_id'], 'price': info['price_info'],
'has_saled': ss})
csv_file.flush()
for reqs in j_ahead:
if reqs["_resourceType"] == 'xhr':
if 'proxy/api/search?' in reqs['request']['url']:
nums = nums + 1
print(nums)
try:
a = reqs['response']['content']['text']
read_json(a)
except:
continue
print('========遍历完成===========')
csv_file.flush()
csv_file.flush()
csv_file.flush()
time.sleep(3)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。