如果拉钩网html页面做了调整,需要重新调整代码
代码如下
#/usr/bin/env python3#coding:utf-8import sysimport jsonimport requests"""Usage: python3 lagou.py"""def get_jobs(pn=1,kw="python"): url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false' payload = { "first":"false","pn":pn,"kd":kw} #payload = {'needAddtionalResult':'false'} rr = requests.post(url,data=payload) #print(r.json()) jobs_data = rr.json() #print(jobs_data["content"]["positionResult"]["result"][0]) jobs = jobs_data["content"]["positionResult"]["result"] for i in jobs: print("学历:" + i["education"]) print("城市:" + i["city"]) # print("福利:" + i["companyLabelList"]) print("薪资:" + i["salary"]) print("职位:" + i["positionName"]) print("要求:" + i["positionAdvantage"]) print("经验:" + i["workYear"]) print("链接:" + "https://www.lagou.com/jobs/" + str(i["positionId"]) + ".html") print()if __name__ == '__main__': #pn表示页数,kw表示关键词搜索 pn = sys.argv[1] kw = sys.argv[2] get_jobs(pn,kw)