Python爬取拉勾网招聘信息
最近自学研究爬虫,特找个地方记录一下代码。就来到了51.先测试一下。第一次发帖不太会。先贴个代码。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#coding=utf-8
import json
import urllib2
import urllib
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
page=1
length=0
index=1
f=open('lagoudata.txt','a+')
while page<5:
if(page==1):
post_data = {'first':'true','kd':'python','pn':page}
else:
post_data = {'first':'false','kd':'python','pn':page}
page=page+1
r = urllib2.Request("http://www.lagou.com/jobs/positionAjax.json?px=default", urllib.urlencode(post_data))
html=urllib2.urlopen(r).read()
hjson=json.loads(html)
result=hjson['content']['result']
# print result
length=length+len(result)
for i in range(len(result)):
string=str(index)+','+result['companyName']+','+result['financeStage']+','+result['positionAdvantage']+','+result['education']+','+result['workYear']+','+result['city']+','+result['salary']
f.write(string)
f.write('\r\n')
index=index+1
#print string
f.close()
print length
因为这边拉钩网返回的json数据,所以要做处理。反正下图是我最后爬的数据
页:
[1]