源码:

 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爬虫(八)的更多相关文章

  1. Python爬虫(八)_Requests的使用

    Requests:让HTTP服务人类 虽然Python的标准库中urllib2模块中已经包含了平常我们使用的大多数功能,但是它的API使用起来让人感觉不太好,而Requests自称"HTTP ...

  2. Python爬虫实战八之利用Selenium抓取淘宝匿名旺旺

    更新 其实本文的初衷是为了获取淘宝的非匿名旺旺,在淘宝详情页的最下方有相关评论,含有非匿名旺旺号,快一年了淘宝都没有修复这个. 可就在今天,淘宝把所有的账号设置成了匿名显示,SO,获取非匿名旺旺号已经 ...

  3. 孤荷凌寒自学python第八十天开始写Python的第一个爬虫10

    孤荷凌寒自学python第八十天开始写Python的第一个爬虫10 (完整学习过程屏幕记录视频地址在文末) 原计划今天应当可以解决读取所有页的目录并转而取出所有新闻的功能,不过由于学习时间不够,只是进 ...

  4. Python爬虫之selenium的使用(八)

    Python爬虫之selenium的使用 一.简介 二.安装 三.使用 一.简介 Selenium 是自动化测试工具.它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏 ...

  5. Python 爬虫从入门到进阶之路(八)

    在之前的文章中我们介绍了一下 requests 模块,今天我们再来看一下 Python 爬虫中的正则表达的使用和 re 模块. 实际上爬虫一共就四个主要步骤: 明确目标 (要知道你准备在哪个范围或者网 ...

  6. 小白学 Python 爬虫(41):爬虫框架 Scrapy 入门基础(八)对接 Splash 实战

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...

  7. python爬虫Scrapy(一)-我爬了boss数据

    一.概述 学习python有一段时间了,最近了解了下Python的入门爬虫框架Scrapy,参考了文章Python爬虫框架Scrapy入门.本篇文章属于初学经验记录,比较简单,适合刚学习爬虫的小伙伴. ...

  8. Python爬虫(1):基础知识

    爬虫基础知识 一.什么是爬虫? 向网站发起请求,获取资源后分析并提取有用数据的程序. 二.爬虫的基本流程 1.发起请求 2.获取内容 3.解析内容 4.保存数据 三.Request和Response ...

  9. Python爬虫入门教程 12-100 半次元COS图爬取

    半次元COS图爬取-写在前面 今天在浏览网站的时候,忽然一个莫名的链接指引着我跳转到了半次元网站 https://bcy.net/ 打开之后,发现也没有什么有意思的内容,职业的敏感让我瞬间联想到了 c ...

  10. Python爬虫与数据分析之模块:内置模块、开源模块、自定义模块

    专栏目录: Python爬虫与数据分析之python教学视频.python源码分享,python Python爬虫与数据分析之基础教程:Python的语法.字典.元组.列表 Python爬虫与数据分析 ...

随机推荐

  1. 输出流格式化(以操纵子方式格式化,以ios类成员函数方式格式化)

    一.以操纵子方式格式化 数据输入输出的格式控制使用系统头文件<iomanip>中提供的操纵符.把它们作为插入操作符<<的输出对象即可.如setiosflags.setw.set ...

  2. 解析URL中的携带的参数到Map

    手动解析URL字符串中的参数,写了一个工具类. final ; final ; public Map<String, String> parseRequestParam(String ur ...

  3. pandas contact 之后,若要用到index列,要记得用reset_index去处理index

    # -*- coding: utf-8 -*- import pandas as pd import sys df1 = pd.DataFrame({ 'A': ['A0', 'A1', 'A2', ...

  4. Atitit.软件仪表盘(7)--温度监测子系统--电脑重要部件温度与监控and警报

    Atitit.软件仪表盘(7)--温度监测子系统--电脑重要部件温度与监控and警报 Cpu温度,风扇转速 主板温度 显卡温度 硬盘温度 电池温度 鲁大师  硬盘温度 Cpu温度  core temp ...

  5. JMeter学习笔记(四)

    1. 断言 断言组件是通过获取服务器响应数据,然后根据断言规则去匹配这些响应数据:匹配到是正常现象,此时我们看不到任何提醒,如果匹配不到,即出现了异常情况,此时JMeter就会断定这个事务失败,那么我 ...

  6. makefile之include

    "include"指示符告诉 make 暂停读取当前的 Makefile,而转去读取"include"指定的一个或者多个文件,完成以后再继续当前 Makefil ...

  7. 每日英语:China Grapples With Genetically Modified Foods

    A Chinese agricultural official's unsupported claims about the carcinogenic risks of consuming genet ...

  8. python中sorted方法和列表的sort方法使用详解

    一.基本形式 列表有自己的sort方法,其对列表进行原址排序,既然是原址排序,那显然元组不可能拥有这种方法,因为元组是不可修改的. 排序,数字.字符串按照ASCII,中文按照unicode从小到大排序 ...

  9. layui的点击table行选中复选框

    $(document).on("click",".layui-table-body table.layui-table tbody tr",function() ...

  10. error: invalid use of incomplete type

    一般出现这种情况都是没有将用到的头文件包含进来 我的情况是在头文件中定义了一个QMenu的指针,在源文件中使用menuBar()函数来返回一个menu指针.我在源文件中包含了文件<QtGui&g ...