import requests
import time
import random
import csv
def get_data():
url = " https://fxg.jinritemai.com/order/torder/searchlist"
param = {
"order_id": "",
"order_status":"",
"final_status":0,
"after_sale_status":"",
"c_type": "",
"pay_type":"",
"product_name": "",
"logistics_id": "",
"logistics_code": "",
"post_receiver": "",
"post_tel": "",
"start_time": "",
"end_time": "",
"start_receipt_time":"",
"end_receipt_time":"",
"timeout": 0,
"badge": 0,
"urge_tag": 0,
"page": 0,
"pageSize":100,
"total":0,
"b_type":"",
"order_supply_type":"",
"order_type": -1,
"is_ad":-1,
"c_biz":"",
"order": "create_time",
"is_desc": "desc",
"__t": int(time.time() * 1000),
"__token": "e77cdc7cfc718e0a32ff1b25215e74b0"
}
header = {
"authority": "fxg.jinritemai.com",
"content-type": "application/json;charset=utf-8",
"user-agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36",
"referer": "https://fxg.jinritemai.com/iview/shopfxg/order/supplyerList",
"cookie": "PHPSESSID=u2m9brhu5g7olnro3k3ficn870; SLARDAR_WEB_ID=b5e3a1fc-378b-46c8-808c-7722a6db8bfb; _ga=GA1.2.1379376415.1576759160; _gid=GA1.2.1338980467.1576759160"
}
page = 0
results = []
while page < 20: # 963
print("正在爬第%s页........" % (page + 1))
param['page'] = page
param["__t"] = int(time.time() * 1000)
data = requests.get(url,params=param,headers=header)
data = data.json()
if data['data']:
for item in data['data']:
name = item['order']['post_receiver']
tel = item['order']['post_tel']
post_addr = item['order']['post_addr']
address = post_addr['province']['name'] + post_addr['city']['name']+ post_addr['town']['name'] + post_addr['detail']
print([name, tel, address])
results.append([name, tel, address])
page += 1
time.sleep(random.randint(1, 3))
with open('results.csv', 'w', encoding='utf-8-sig') as f:
csv_writer = csv.writer(f)
csv_writer.writerow(['姓名', '手机号', '地址'])
csv_writer.writerows(results)
if __name__ == '__main__':
get_data()