class LaoGo(object):
def __init__(self):
self.url="http://www.lagou.com/lbs/getAllCitySearchLabels.json"
self.headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36'}
def get_down(self):
response=requests.get(url=self.url,headers=self.headers)
w=response.text
return w
def zhuan(self,w):
w=la.get_down()
qq=json.loads(w)
return qq
def write(self,qq):
qq=la.zhuan(la.get_down())
with open('city.json',mode='w',encoding='utf-8') as w:
json.dump(qq,w,ensure_ascii=False)
print("oooooooooooooooooooooooooooooooooooooooo")
with open('city.json',mode='r',encoding='utf-8') as f:
ww=json.load(f)
print(ww)
if __name__ == '__main__':
la=LaoGo()
# print(la.get_down())
print("---------------------------------------------------------------------------------")
print(la.zhuan(la.get_down()))
print("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")
la.write(la.zhuan(la.get_down()))
转载于:https://www.cnblogs.com/liang715200/p/10151514.html