import requests
import csv
import random
f = open('vc.csv',mode='a',encoding='utf-8',newline='')
csv_writer = csv.DictWriter(f,fieldnames=[
'客户姓名',
'订单编号',
'pin'
])
csv_writer.writeheader()
list_url = 'https://itemext.jd.com/sub_itemext/workorder/listJsonData'
headers = {
'Cookie':'*'
'Origin':'https://itemext.jd.com',
'Referer':'https://itemext.jd.com/sub_itemext/workorder/list',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
}
for i in range(1,10):
data = {
'length': '10',
'page': f'{i}',
'sidx': 'create_date',
'sord': 'desc',
'status': '0',
'createDateFrom': '2023-06-09',
'createDateTo': '2023-09-08'
}
list_resp = requests.post(list_url,headers=headers,data=data)
if list_resp.json()['jsonList'] is None:
break
list_resp_json = list_resp.json()['jsonList']
for info in list_resp_json:
erpName = info['erpName']
orderId = info['orderId']
url = f'https://itemext.jd.com/sub_itemext/workorder/showOrderByWod?orderId={orderId}'
resp = requests.get(url,headers=headers)
resp_json = resp.json()
pin = resp_json['pin']
dit = {
'客户姓名':erpName,
'订单编号':orderId,
'pin':pin
}
csv_writer.writerow(dit)
print(f'第{i}页{erpName}写入成功')
需要开始学习下,新的知识,一直循环嵌套不行啊