代码如下:
import urllib.request
import jsonpath
import json
url='https://www.lagou.com/lbs/getAAllCitySearchLaabels.json'
request=urllib.request.Request(url)
response=urllib.request.urlopen(request)
html=response.read()
print(html)
jsonobj=json.loads(html)
print(jsonobj,type(jsonobj))
city_list=jsonpath.jsonpath(jsonobj,'$..name')
print(city_list,type(city_list))
file= open('city.json','w')
content=json.dumps(city_list,ensure_ascii=False)
print(content)
file.write(content)
file.close()