http://www.ptpress.com.cn/

优化代码import json import requests from lxml import etree import pandas as pd import time #url='https://www.ptpress.com.cn/masterpiece/getMasterpieceListForPortal' #https://www.ptpress.com.cn/recommendBook/getRecommendTupeListForPortal #http://www.ptpress.com.cn/masterpiece/getMasterpieceListForPortal url='https://www.5iai.com/api/enterprise/job/public/es?pageSize=10&pageNumber=1'#目标数据文件的url #url = ' https://www.5iai.com/api/enterprise/job/public/es?pageSize=10&pageNumber=2&willNature=&function=&wageList=%255B%255D&workplace=&keyword=' for i in range (1,20): response=requests.get(url) aa=response.text print(type(aa)) json_text=json.loads(aa) print(type(json_text)) json_text.keys() bb=json_text['data'] print(type(bb)) print(bb.keys()) cc= bb['content'] print(type(cc)) ee0=cc[0] #是第一条信息 ee1=cc[1] len(cc)#是cc的第一个招聘的第一页招聘信息,是列表类型 print(type(ee0)) ee0.keys() ee1.keys()#0和1的的字典的键都是一样的 data=pd.DataFrame(cc) data.columns ff=data['enterpriseAddress'] print(type(ff)) gg0=ff[0] gg1=ff[1] hh0=gg0['detailedAddress'] hh1 = gg1['detailedAddress'] hh3= ff[2]['detailedAddress'] hh4= ff[3]['detailedAddress'] hh5=data['enterpriseAddress'] [4]['detailedAddress'] data['工作地址']=ff.apply(lambda x:x['detailedAddress']) data['工作地址']=data['enterpriseAddress'].apply(lambda x:x['detailedAddress']) data['工作城市']=data['enterpriseAddress'].apply(lambda x:x['cityCode']) kk=data['enterpriseExtInfo'] print(type(kk)) ll0=kk[0] data['公司名称']=data['enterpriseExtInfo'].apply(lambda x:x['shortName']) data['行业']=data['enterpriseExtInfo'].apply(lambda x:x['industry']) data['人员规模']=data['enterpriseExtInfo'].apply(lambda x:x['personScope']) data['企业性质']=data['enterpriseExtInfo'].apply(lambda x:x['econKind']) data.keys() colNames=['positionName','minimumWage','maximumWage','exp','educationalRequirements','工作地址','工作城市','公司名称','行业','人员规模','企业性质'] data_drop=data[colNames] #https: // www.5iai.com / api / enterprise / job / public?id = 1657941238357299201 #https: // www.5iai.com / api / enterprise / job / public?id = 1657941238353104896 data['id'] #print(type(data['id'])) #suburl='https://www.5iai.com/api/enterprise/job/public?id=1657941238353104896' jobDes = [] for idd in data['id']: suburl = 'https://www.5iai.com/api/enterprise/job/public?id={}'.format(idd) sub_response=requests.get(suburl) subb=sub_response.text #print(type(subb)) sub_text=json.loads(subb) #print(type(sub_text)) sub_text.keys subaa=sub_text['data'] #print(type(subaa)) subaa.keys jobms=subaa['jobRequiredments'] #print(type(jobDes)) jobDes.append(jobms) time.sleep(2) data_drop['职位描述']=jobDes
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值