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爬虫与数据分析 ...
随机推荐
- How to authenticate a user by uid and password?
原文地址:Authentication options | Basic authorization If you want to use simple binds with user DN and p ...
- windows系统同时连接多个openvpn账户
windows系统同时连接多个openvpn账户. 前提 客户端系统:Windows7 64位 OpenVPN版本:OpenVPN 2.3.10 Windows 64位 一.安装 1.安装目录 D:\ ...
- laravel-v5.1数据库连接文件是.env文件
- 微信公众平台消息接口PHP版
使用前提条件:拥有一个公网上的HTTP服务器主机空间,具有创建目录.上传文件等权限.推荐新浪的SAE.http://sae.sina.com.cn/ 首先请注册微信公众平台的账号,注册地址:http: ...
- spring4.3+mybatis3.4+freemark+log4j2+fastjson整合
2017-7-1 更新 spring 版本 4.3.9 更新mybatis 为3.4.3 0.先写下文件结构防止配置放错地方 1.首先发下maven配置 <properties> < ...
- Mysql 数据库数值类型详解
MySQL 支持所有标准SQL 中的数值类型,其中包括严格数值类型(INTEGER.SMALLINT.DECIMAL 和NUMERIC),以及近似数值数据类型(FLOAT.REAL 和DOUBLE P ...
- mybatis 参数说明
1 简单参数 <select id="selectUsers" resultType="User"> select id, username, pa ...
- cadence orcad查找技巧
本文讲述了如何在OrCAD原理图中根据元件位号或者元件值快速查找元件的两种方法. 方法一:在.obj页面的“File”标签下查找元件. 方法二:在.obj页面的“Hierarchy”标签下查找元件. ...
- java 清除 bom
参考工具 http://akini.mbnet.fi/java/unicodereader/ Utf8BomRemover 清除bom的方法 package cn.com.do1.component ...
- jquery文件导入问题
开发前台web,导入jquery文件的时候最好用 <script type="text/javascript" src="path"></sc ...