You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.9 KiB
39 lines
1.9 KiB
import urllib.request
|
|
import jsonpath
|
|
import json
|
|
|
|
def requests():
|
|
url='https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1762327197991_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'
|
|
headers = {
|
|
'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
|
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
'Bx-V': '2.5.31',
|
|
'Cookie': 'cna=G8+LHyl+PBICAcpkzqO4A3py; t=e395f55297a2d27551f835c2f5273fef; cookie2=183a0e8a811413580e7879faf4a524aa; v=0; _tb_token_=7e35845b43f6b; xlly_s=1; ariaDefaultTheme=default; ariaFixed=true; ariaReadtype=1; ariaoldFixedStatus=false; ariaStatus=false; isg=BNLSiEU97oJ55R2VL0-PDeTRI5i049Z95Mg555wqggVwr3OphHbzjWWBHwuT304V',
|
|
'Referer': 'https://dianying.taobao.com/',
|
|
'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
|
|
'Sec-Ch-Ua-Mobile': '?0',
|
|
'Sec-Ch-Ua-Platform': 'Windows',
|
|
'Sec-Fetch-Dest': 'empty',
|
|
'Sec-Fetch-Mode': 'cors',
|
|
'Sec-Fetch-Site': 'same-origin',
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
|
'X-Requested-With': 'XMLHttpRequest' }
|
|
request = urllib.request.Request(url=url, headers=headers)
|
|
return request
|
|
def contents(request):
|
|
response = urllib.request.urlopen(request)
|
|
content = response.read().decode('utf-8')
|
|
return content
|
|
def down_load(content):
|
|
with open('³ÇÊÐÐÅÏ¢.json','w',encoding='utf-8') as f:
|
|
f.write(str(content)+'\n')
|
|
|
|
if __name__ == '__main__':
|
|
request = requests()
|
|
content = contents(request)
|
|
new_content = content.split('(')[1].split(')')[0]
|
|
down_load(new_content)
|
|
obj = json.load(open('³ÇÊÐÐÅÏ¢.json', 'r', encoding='utf-8'))
|
|
city_list = jsonpath.jsonpath(obj, '$..regionName')
|
|
down_load(city_list)
|