拉勾网爬虫-python语言实现
来源:互联网 发布:使命召唤13优化怎么样 编辑:程序博客网 时间:2024/05/30 19:32
以下实现拉勾网上面的北京python的招聘岗位的相关信息,包括公司名称,工资,公司简单介绍,公司地址
初始页面为http://www.lagou.com/zhaopin/Python/?labelWords=label
文件存储在同一个目录下的12345.txt中
#coding=utf-8import urllib2from bs4 import BeautifulSoup#定义一个伪装的头文件sendHeaders = { 'User-Agent':'Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0', 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Connection':'keep-alive'}#临时存储文件为saveFile = open('12345.txt','a+')k=1 #统计一共的味信息数量for i in range(1,31): # 一共就30页 每次加一个页面,urltemp 后面会+1 urltemp= 'http://www.lagou.com/zhaopin/Python/' url = urltemp+str(i)+"?filterOption=3" # 翻页操作+1 #使用urllib2来伪造访问的头 requeset = urllib2.Request(url,headers=sendHeaders) html = urllib2.urlopen(requeset) #通过beautifulsoup处理页面 soup = BeautifulSoup(html,'lxml') #读出每个页面的class内容为con_list_item的列表 infoList = soup.select('.con_list_item') for j in range(len(infoList)): print('正在打印第%d页第%d条'%(i,k)) #保存公司名称 companyName=infoList[j].attrs['data-company'] saveFile.write(str(k)+'.'+companyName.encode('utf-8')+':') #保存公司薪水 companySalary=infoList[j].attrs['data-salary'] saveFile.write(companySalary.encode('utf-8')+',') #保存职位名称 positationName = infoList[j].attrs['data-positionname'] saveFile.write(positationName.encode('utf-8')+',') #保存公司地址 companyAddrTemp =infoList[j].select('.add')[0].get_text() saveFile.write(companyAddrTemp.encode('utf-8')+',') #保存职位表述 positionInfoTemp = infoList[j].select('.li_b_l')[1].get_text() saveFile.write(positionInfoTemp.encode('utf-8')+'\n') k += 1saveFile.close()
0 0
- 拉勾网爬虫-python语言实现
- Python实现网络爬虫
- Python实现网络爬虫
- Python实现网络爬虫
- python实现网络爬虫
- python实现网络爬虫
- [Python] 实现网络爬虫
- python实现网络爬虫
- Python实现网络爬虫
- [Python] 实现网络爬虫
- python实现图片爬虫
- Python实现网络爬虫
- Python 实现网络爬虫
- Python实现网络爬虫
- python实现并行爬虫
- python 简单爬虫实现
- python实现网络爬虫
- Python实现简单爬虫
- Java单例模式浅谈
- 微软面试百题017——哈希查找/优先队列
- SpringMVC接收页面表单参数
- unity Camera 属性详解
- Fragment(碎片)(2)-的生命周期
- 拉勾网爬虫-python语言实现
- C++专题总结之输入输出
- PPT超炫资源
- hdu 1213 求连通分支个数
- 安卓中在AndroidStudio集成第三方支付宝(史上最详细版)
- PCL编程-法向量计算
- cocos lua 实现原声语音 流程概述
- 6、表格控件GirdPanel及EditorGrid使用
- idea自动导入jar包的快捷键