源码:

 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. javascript 图片预加载

    <!DOCTYPE > <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ...

  2. Google发展史 Google十三年

    http://blog.csdn.net/terryzero/article/details/5910617 "1997年9月15日,Larry Page 和 Sergey Brin 正式注 ...

  3. FFmpeg 向视频中添加文字

    原文地址:http://www.cnblogs.com/wanggang123/p/6707985.html FFmpeg支持添加文字功能,具体如何将文字叠加到视频中的每一张图片,FFmpeg调用了文 ...

  4. EMQ配置

    参考官方配置页面:http://emqtt.com/docs/v2/tune.html Linux 操作系统参数系统所有进程可打开的文件数量官方配置: sysctl -w fs.file-max=20 ...

  5. EM 算法 实例

    #coding:utf-8 import math import copy import numpy as np import matplotlib.pyplot as plt isdebug = T ...

  6. atitit.高性能遍历 文本文件行 attilax总结

    atitit.高性能遍历 文本文件行 attilax总结 文件读写有以下几种常用的方法 1 通常io读取2.5s 1 nio读取或许越高的.. 2 NIO通常采用Reactor模式,AIO通常采用Pr ...

  7. Atitit. 解决unterminated string literal 缺失引号

    Atitit. 解决unterminated string literal 缺失引号 原因:::或许string没使用引号括号起来...missingMessage缺失了一个单个的引号 Error:  ...

  8. redhat yum替换成CentOS yum 并修改源

    wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm wge ...

  9. IOS 获取设备屏幕的尺寸

    // 不包含状态栏 CGRect rect1 = [UIScreen mainScreen].applicationFrame; // 包含状态栏(整个屏幕) CGRect rect2 = [[UIS ...

  10. @XStreamAlias使用

    @XStreamAlias使用 一. 特点: 简化的API; 无映射文件; 高性能,低内存占用; 整洁的XML; 不需要修改对象;支持内部私有字段,不需要setter/getter方法 提供序列化接口 ...