网络爬虫

#encoding:utf-8
import requests
import xlwt


book = xlwt.Workbook(encoding='utf-8', style_compression=0)
sheet = book.add_sheet('test', cell_overwrite_ok=True)
sheet.write(0, 0, '岗位')
sheet.write(0, 1, '地区')
sheet.write(0, 2, '薪资')
sheet.write(0, 3, '公司')




def main(num,a):


    headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
    }


    r = requests.get('http://nb.58.com/tech/pn'+str(num), headers=headers)
    from bs4 import BeautifulSoup


    soup = BeautifulSoup(r.text, 'html.parser')
    for i in soup.find_all(attrs={'class': 'job_item clearfix'}):


        area = i.div.div.a.span.string
        salary = i.div.contents[3].contents[0]
        job = i.div.div.a.contents[3].string
        coporate=i.contents[3].div.a.string


        sheet.write(a, 1, area.split())
        sheet.write(a, 2, salary)
        sheet.write(a, 0, job.split())
        sheet.write(a, 3, coporate.split())
        a = a + 1
    return a




if __name__ == '__main__':
    a=1
    for num in range(1,54):
        a=main(num,a)




book.save(r'E:\test91.xls')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值