#3156874915
import requests from requests import post from json import dumps from re import findall
# xiong xiao hui #爬取某米有品的手机信息 def get_content(need_item="手机"): url = "https://www.xiaomiyoupin.com/mtop/market/search/v2/doSearch" headers = { 'cookie': "source=duomai_244732316_3.duomai.244732316.1662528468494.748171370.1.2209061327484934808560; youpindistinct_id=1831144e6db680-0ced92fce3ade7-78565470; mjclient=PC; youpin_sessionid=18311fa4db8-0d23b94908e82f-238a", 'referer': "https://www.xiaomiyoupin.com/", 'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27" } # 这是data的类型 data = [{}, {"query": [{"queryName": "手机", "queryType": 0, "rule": []}], "sortBy": 0, "pageIdx": 0, "strategyInfo": None, "filter": None, "baseParam": {"imei": "", "clientVersion": "", "ypClient": 3}, "source": "searchPage", "requestId": "5707393421591074", "clientPageId": "3732617895117638", "recentAddress": None, "requestExtraInfo": {}, "pageSize": 20}] data123_xiongxiaohui = dumps(data) #将python对象编码成Json字符串 response = post(url=url, headers=headers, data=data_xiongxiaohui) response.encoding = 'utf-8' qwe=response.json() c=qwe["data"]['data']['goods'] for i in c: c=i['data']['goodsInfo']['summary'] c11=i['data']['goodsInfo']['name'] x33=int(i['data']['goodsInfo']['marketPrice'])/100 im4=i['data']['goodsInfo']['imgSquare'] print('手机名字::{},===介绍::{}===价格::{}====图片::{}'.format(c11,c,x33,im4)) if __name__ == '__main__': get_content()
标签:__,某米,import,爬取,goodsInfo,有品,手机,data From: https://www.cnblogs.com/xxh12/p/16662941.html