import requests
import re
class HandleLaGou(object):
def __init__(self):
#使用session保存cookie休息
self.lagou_session = requests.session()
self.header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
}
self.city_list = ""
#获取全国所有城市列表的方法
def handle_city(self):
city_search = re.compile(r'zhaopin/">(.*?)</a>')
city_url = "https://www.lagou.com/jobs/allCity.html"
city_result = self.handle_request(method="GET",url=city_url)
print(city_result)
def handle_request(self,method,url,data=None,info=None):
if method == 'GET':
response = self.lagou_session.get(url=url,headers=self.header)
return response.text
if __name__ == '__main__':
lagou = HandleLaGou()
lagou.handle_city()