Python爬虫(八)
源码:
import requests
import re
from my_mysql import MysqlConnect
import time,random # 获取招聘详情链接
def get_urls(page, headers):
url = 'https://hr.tencent.com/position.php?lid=&tid=&keywords=python&start=page'.format(page)
response = requests.get(url, headers=headers)
pat = r'href="(position_detail.*?)">'
url_list_bytes = re.findall(pat.encode('utf-8'), response.content)
return url_list_bytes # 获取招聘详情
def get_info(url, headers):
response = requests.get(url, headers=headers)
html_bytes = response.content
# print(html_bytes) # title 标题
pat = r'id="sharetitle">(.*?)</td>'
res = re.search(pat.encode('utf-8'), html_bytes)
title = res.group(1).decode('utf-8')
# address 地点
pat = r'工作地点:</span>(.*?)</td>'
res = re.search(pat.encode('utf-8'), html_bytes)
address = res.group(1).decode('utf-8')
# types 类别
pat = r'职位类别:</span>(.*?)</td>'
res = re.search(pat.encode('utf-8'), html_bytes)
types = res.group(1).decode('utf-8')
# counts 人数
pat = r'招聘人数:</span>(.*?)</td>'
res = re.search(pat.encode('utf-8'), html_bytes)
counts = res.group(1).decode('utf-8')
# duty 职责
pat = r'工作职责.*?<ul class="squareli">(.*?)</ul>'
res = re.search(pat.encode('utf-8'), html_bytes)
duty_str = res.group(1).decode('utf-8')
pat = r'<li>(.*?)</li>'
duty = re.findall(pat,duty_str)
duty = ('\n').join(duty)
# requires 要求
pat = r'工作要求.*?<ul class="squareli">(.*?)</ul>'
res = re.search(pat.encode('utf-8'), html_bytes)
requires_str = res.group(1).decode('utf-8')
pat = r'<li>(.*?)</li>'
requires = re.findall(pat, requires_str)
requires = ('\n').join(requires)
return title,address,types,counts,duty,requires if __name__ == '__main__':
mc = MysqlConnect('127.0.0.1','root','','homework')
sql = "insert into tencentzp(title,address,types,counts,duty,requires) values(%s,%s,%s,%s,%s,%s)"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
for page in range(0,200,10):
url_list_bytes = get_urls(page,headers)
# print(url_list_bytes)
for url in url_list_bytes:
# print(url.decode('utf-8'))
url = 'https://hr.tencent.com/' + url.decode('utf-8')
info = get_info(url,headers)
print(info)
mc.exec_data(sql,info)
time.sleep(random.random()*5)
Python爬虫(八)的更多相关文章
- Python爬虫(八)_Requests的使用
Requests:让HTTP服务人类 虽然Python的标准库中urllib2模块中已经包含了平常我们使用的大多数功能,但是它的API使用起来让人感觉不太好,而Requests自称"HTTP ...
- Python爬虫实战八之利用Selenium抓取淘宝匿名旺旺
更新 其实本文的初衷是为了获取淘宝的非匿名旺旺,在淘宝详情页的最下方有相关评论,含有非匿名旺旺号,快一年了淘宝都没有修复这个. 可就在今天,淘宝把所有的账号设置成了匿名显示,SO,获取非匿名旺旺号已经 ...
- 孤荷凌寒自学python第八十天开始写Python的第一个爬虫10
孤荷凌寒自学python第八十天开始写Python的第一个爬虫10 (完整学习过程屏幕记录视频地址在文末) 原计划今天应当可以解决读取所有页的目录并转而取出所有新闻的功能,不过由于学习时间不够,只是进 ...
- Python爬虫之selenium的使用(八)
Python爬虫之selenium的使用 一.简介 二.安装 三.使用 一.简介 Selenium 是自动化测试工具.它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏 ...
- Python 爬虫从入门到进阶之路(八)
在之前的文章中我们介绍了一下 requests 模块,今天我们再来看一下 Python 爬虫中的正则表达的使用和 re 模块. 实际上爬虫一共就四个主要步骤: 明确目标 (要知道你准备在哪个范围或者网 ...
- 小白学 Python 爬虫(41):爬虫框架 Scrapy 入门基础(八)对接 Splash 实战
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- python爬虫Scrapy(一)-我爬了boss数据
一.概述 学习python有一段时间了,最近了解了下Python的入门爬虫框架Scrapy,参考了文章Python爬虫框架Scrapy入门.本篇文章属于初学经验记录,比较简单,适合刚学习爬虫的小伙伴. ...
- Python爬虫(1):基础知识
爬虫基础知识 一.什么是爬虫? 向网站发起请求,获取资源后分析并提取有用数据的程序. 二.爬虫的基本流程 1.发起请求 2.获取内容 3.解析内容 4.保存数据 三.Request和Response ...
- Python爬虫入门教程 12-100 半次元COS图爬取
半次元COS图爬取-写在前面 今天在浏览网站的时候,忽然一个莫名的链接指引着我跳转到了半次元网站 https://bcy.net/ 打开之后,发现也没有什么有意思的内容,职业的敏感让我瞬间联想到了 c ...
- Python爬虫与数据分析之模块:内置模块、开源模块、自定义模块
专栏目录: Python爬虫与数据分析之python教学视频.python源码分享,python Python爬虫与数据分析之基础教程:Python的语法.字典.元组.列表 Python爬虫与数据分析 ...
随机推荐
- 执行pig出错Unhandled internal error. Found interface jline.Terminal, but class was expected
执行pig时报例如以下错误 2015-07-14 10:41:12,869 [main] ERROR org.apache.pig.Main - ERROR 2998: Unhandled inter ...
- ibatis/mybatis显示sql语句 log4j.properties配置文件
将ibatis/mybatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运行的sql语句,方便调试: ### 设置Logger输出级别和输出目的地 ### log4j.rootL ...
- Android 设计的几处硬伤
[核心提示] 一些 Android App 不仅仅是设计风格的问题,产品交互上也比较混乱,造成用户体验不一致,这一部分原因也是 Android 当初设计时遗留的问题. 前几天看到 NovaDNG 介绍 ...
- 关注C++细节——C++11新标准之decltype的使用注意
c++11新特性--decltype decltype是C++11加入的一个新的keyword,目的是选择并返回操作数的数据类型,重要的是,在此过程中编译器分析表达式并得到它的类型,却不实际计算表达式 ...
- 解析URL中的携带的参数到Map
手动解析URL字符串中的参数,写了一个工具类. final ; final ; public Map<String, String> parseRequestParam(String ur ...
- Mysql 比较运算符详解
熟悉了最简单的算术运算符,再来看一下比较运算符.当使用SELECT 语句进行查询时,MySQL允许用户对表达式的左边操作数和右边操作数进行比较,比较结果为真,则返回1,为假则返回0,比较结果不确定则返 ...
- JAVA数字特征值
数字特征值(5分) 题目内容: 对数字求特征值是常用的编码算法,奇偶特征是一种简单的特征值.对于一个整数,从个位开始对每一位数字编号,个位是1号,十位是2号,以此类推.这个整数在第n位上的数字记作x, ...
- NIO--SocketChannel发送HTTP请求
import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChanne ...
- Qt禁止调整窗口的大小
项目中使用的是基于对话框的程序,所以限制调整窗口大小会比较合适,下面是两种方法. 1.使用代码修改 #include "dialog.h" #include "ui_di ...
- VS调试-添加命令行参数
Project -> Properties -> Configuration Properties -> Debugging 在Command Arguments里填上即可