我爱我家租房信息

import requests, re, time
from lxml import etree
from urllib import parse
from mysql_test import mysql_connect



def txzhaopin(num):
    for page in range(num):
        page*=10
        mc = mysql_connect()
        sql = 'insert into txzhaopin (title, location, type, num, detail, request) values (%s,%s,%s,%s,%s,%s)'

        url = 'https://hr.tencent.com/position.php?keywords=&lid=0&tid=87&start=%d' % page
        headers = {
            'Cookie': 'PHPSESSID=ipcbv7o54krhuhgf9e1cc5km07; pgv_pvi=5188443136; pgv_si=s6186220544',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3377.1 Safari/537.36',
        }

        response = requests.get(url, headers=headers)
        html_ele = etree.HTML(response.text)
        tr_ele = html_ele.xpath('//table[@class="tablelist"]/tr')[1:-1]
        for tr in tr_ele:
            href_ele = tr.xpath('./td/a/@href')
            sec_url = parse.urljoin(url, href_ele[0])
            print(sec_url)
            res = requests.get(sec_url, headers=headers)
            html_ele = etree.HTML(res.text)
            sec_tr_ele = html_ele.xpath('//table[@class="tablelist textl"]/tr')[:4]
            title = sec_tr_ele[0].xpath('./td')[0].text
            print(title)
            location = sec_tr_ele[1].xpath('./td[1]/text()')[0]
            print(location)
            type = sec_tr_ele[1].xpath('./td[2]/text()')[0]
            print(type)
            num = re.search('\d+',sec_tr_ele[1].xpath('./td[3]/text()')[0]).group(0)
            print(num)
            detail = ''.join(sec_tr_ele[2].xpath('./td/ul/li/text()'))
            print(detail)
            request = ''.join(sec_tr_ele[3].xpath('./td/ul/li/text()'))
            print(request)
            data = (title, location, type, num, detail, request)
            mc.mysql_insert_modify(sql, data)
            time.sleep(1)


if __name__ == '__main__':
    num = 3
    txzhaopin(num)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值