def get_json(kind, city, page=1,): data = { 'first':"true", 'pn':page, 'kd':kind } kw = {'px':'default', 'city':city, 'needAddtionalResult':'false'} user_agent_list = ['Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50', 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1 QQBrowser/6.9.11079.201'] user_agent = random.choice(user_agent_list) print('1:',user_agent) header = { 'Host': 'www.lagou.com', 'Referer': 'https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=', 'User-Agent': user_agent } print(header) # 设置代理 proxies = [ {'http': '140.143.96.216:80', 'https': '140.143.96.216:80'}, {'http': '119.27.177.169:80', 'https': '119.27.177.169:80'}, {'http': '221.7.255.168:8080', 'https': '221.7.255.168:8080'} ] # 请求的url # url = 'https://www.lagou.com/jobs/positionAjax.json?city=%E5%8C%97%E4%BA%AC&needAddtionalResult=false' url = 'https://www.lagou.com/wn/zhaopin?pn=' #使用代理访问 # response = requests.post(url, headers=header, data=param, proxies=proxies) response = requests.post(url, params=kw, headers=header, data=data) print(response.text) response.encoding='utf-8' if response.status_code == 200: response = response.json() return response['content']['positionResult'] return None
时间: 2023-06-20 10:10:21 浏览: 393
_dead_repo_pipette_:new_data =移液器(数据,模板)
这是一个函数,用于获取拉钩网站上的职位信息。它接受以下参数:
- kind:职位类型,比如python、java等
- city:城市名称,比如北京、上海等
- page:页码,可选参数,默认值为1
函数会返回拉钩网站上对应页码、城市和职位类型的职位信息。它使用了随机的User-Agent和代理访问拉钩网站。
阅读全文