import requests
import re
import json
def url_open(key_word):
url='https://ai.taobao.com/search/index.htm'
headers ={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'}
params={'key':key_word,'sort':'biz30day'}
res = requests.get(url,headers=headers,params=params)
return res
def main():
key_word=input('请输入商品关键字:')
res = url_open(key_word)
## with open('0.txt','w',encoding='utf-8')as f:
## f.write(res.text)
## with open('0.txt','r',encoding='utf-8')as f:
## a = f.read()
res_js = re.search(r'var _pageResult = (.*?);\n',res.text)
## with open('4.txt','w',encoding='utf-8')as f:
## f.write(res_js.group(1))
target = res_js.group(1)
d_json =json.loads(target)
data = d_json['result']['auction']
for each in data:
print(each['nick'],each['biz30Day'])
if __name__=='__main__':
main()
|