requests庫例項
阿新 • • 發佈:2020-09-12
import requests import json import urllib3 urllib3.disable_warnings() def orderDetail(): url='https://appapi.dmall.com/app/apporder/orderdetail' header = { "Host": "appapi.dmall.com", "device": "iPhone11,8", "deliveryLat": "39.976565", "appName": "com.dmall.dmallmainapp", "dev_type": "iPhone", "areaId": "110108", "platform": "IOS", "smartLoading": "1", "Accept": "*/*", "isOpenNotification": "0", "wifiState": "1", "ticketName": "7AAA51A6C3C8A056016F24C7BBB4EEF046C269102C6E8FA14D578B696D08DECF45D415AC23E709AA9966C89D81D3BC313B9A3F70789C8FA2CBE1CBB7B91D86D4B5872BDA23B0A93B8AED2D1DB2F46D7CCC5CA86A88B2C93B94777CCF29AB09C18E33FB3186A1348F7C9CC8404C0733D9A7EC2A7BC9D8C48147C67054EA0EC56B", "screen": "896*414", "sessionId": "1A30952882694AD984D27D4C8A912840", "User-Agent": "dmall/4.8.2 (iPhone; iOS 13.6.1; Scale/2.00)", "businessCode": "1", "channelId": "APPSTORE", "xyz": "ac", "storeId": "12672", "version": "4.8.2", "uuid": "5e72995bf78207f156d9ee14dc17a489701836f0", "apiVersion": "4.8.2", "deliveryLng": "116.320725", "Content-Length": "114", "Accept-Encoding": "gzip, deflate, br", "venderId": "86", "currentTime": "1599891840927", "storeGroupKey": "308fadfa62edb5933121b0b9aa05cc4e@MS0xMjY3Mi04Ng", "utmSource": "1111.3", "networkType": "1", "Accept-Language": "zh-Hans-CN;q=1", "sysVersion": "13.6.1", "lng": "116.320205", "idfa": "29B52893-C109-425E-A3D4-543AEC01B2B7", "platformStoreGroupKey": "bce9caa286921534eef7d9f525949a03@MTY1LTE1ODgz", "env": "app", "cid": "171976fa8a31883de6d", "recommend": "1", "dev_carrier": "", "Content-Type": "application/x-www-form-urlencoded", "lat": "39.976481", "Connection": "keep-alive", "token": "999fb47b-7e12-4bc5-8c54-f92e1a0b1300", "appMode": "online", "userId": "163863113" } param = {"orderId":"262462194513","reqType":0,"isFront":1,"dBusiness":"0"} data = "param=%s" %json.dumps(param, ensure_ascii=False) r = requests.post(url=url,headers = header,data = data ,verify = False) resJson = json.loads(r.text) address = resJson['data']['frontOrderVO']['consignee']['addressDetail'] name = resJson['data']['frontOrderVO']['orderStatusName'] price = resJson['data']['smallTicketInfo'][0]['smallTicketLinePriceWithSymbol'] wareInfoList = {“門店地址": address,"訂單狀態":name,"價格":price} # wareInfoList = [] # wareInfoList.append(resJson['data']['frontOrderVO']['consignee']['addressDetail']) # print(resJson['data']['frontOrderVO']['consignee']['addressDetail']) # wareInfoList.append(resJson['data']['frontOrderVO']['orderItemList']['orderStatusName']) print(wareInfoList) if __name__=="__main__": orderDetail()