博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
腾讯招聘信息爬取
阅读量:4610 次
发布时间:2019-06-09

本文共 2187 字,大约阅读时间需要 7 分钟。

1 import requests 2 from lxml import etree 3 import mysqlhelper 4  5 myhelper = mysqlhelper.MysqlHelper() 6 sql = 'INSERT INTO tenxunzhaoping (title, duty, people_num, address,addtime) VALUES(%s, %s, %s, %s,%s)' 7  8 headers = { 9     "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",10     "Accept-Encoding": "gzip, deflate, br",11     "Accept-Language": "zh-CN,zh;q=0.9",12     "Cache-Control": "no-cache",13     "Connection": "keep-alive",14     "Cookie": "pgv_pvi=5854498816; _ga=GA1.2.608623393.1534496276; pt2gguin=o1900227304; PHPSESSID=0smi013v1lr7r3ki2aqtacp493; pgv_si=s8414673920",15     "Host": "hr.tencent.com",16     "Pragma": "no-cache",17     "Referer": "https://hr.tencent.com/position.php?&start=10",18     "Upgrade-Insecure-Requests": "1",19     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",20 21 }22 # url = 'https://hr.tencent.com/position.php?keywords=&lid=2156&start=0#a'23 base_url = 'https://hr.tencent.com/position.php?keywords=&tid=0&lid=2156&start=%s#a'24 25 for i in range(0,300,10):26     url = base_url % i27     response = requests.get(url, headers=headers)28     html_ele = response.text29     # print(html_ele)30     ver = etree.HTML(html_ele)31     # print(ver)32     for v in range(2,12):33         li_list = ver.xpath('//div[@id="position"]/div/table/tr[{}]'.format(v))34         # print(li_list)35         for li_ele in li_list:36             # if li_ele == li_ele.xpath('./tr[1]')[0].text:37             #     continue38             title = li_ele.xpath('./td/a')[0].text39             print(title)40             duty = li_ele.xpath('./td[2]')[0].text41             print(duty)42             people_num = li_ele.xpath('./td[3]')[0].text43             print(people_num)44             address = li_ele.xpath('./td[4]')[0].text45             print(address)46             addtime = li_ele.xpath('./td[5]')[0].text47             print(addtime)48 49             data = (title, duty, people_num, address,addtime)50             myhelper.execute_modify_sql(sql, data)

 

转载于:https://www.cnblogs.com/daihao9527/p/9503177.html

你可能感兴趣的文章
前端性能优化方法
查看>>
Docker镜像拉不下来?试试这些
查看>>
实例11 加密可以这样简单(位运算)
查看>>
[告知]在评论中发布广告者必删!
查看>>
判断一个js对象是不是数组
查看>>
Vue-详解设置路由导航的两种方法: <router-link :to="..."> 和router.push(...)
查看>>
c# 实现电脑系统音量的增加,减少,静音等。
查看>>
Block那些事儿
查看>>
突然的感触,关乎技术上的
查看>>
再说单例模式的线程安全问题
查看>>
<<、>>、>>>移位操作
查看>>
HDU 3572 Task Schedule(拆点+最大流dinic)
查看>>
HDU——1405The Last Practice(试手map)
查看>>
PAT 基础编程题 4-11 求自定类型元素序列的中位数(希尔排序)
查看>>
PHP implode() 函数由数组合并字符串
查看>>
软件测试的生命周期&测试流程
查看>>
深入SpringMVC视图解析器
查看>>
hi~大家好,特地出来解释下最近为啥都不更新了!
查看>>
python linux 开启 一个新端口 查看文件
查看>>
ubuntu 常用命令
查看>>