提取牛客校招日历时间_python

本文介绍了如何使用BeautifulSoup库从牛客网的校招日历页面抓取公司名称和时间信息,通过HTML源代码操作实现数据提取并保存为Excel。

step1:将网页源代码复制到txt文件

牛客的校招日历网址:https://www.nowcoder.com/school/schedule

我用的是edge浏览器,按F12查看源代码。

点击右上角画框的图标,鼠标移动到页面上找到想要的区域,可看到我想要的蓝色mask区域对应右面的<ul>

鼠标右键点击这部分源代码,复制元素到b.txt中

(复制前注意把页面多向下滚滚多加载些公司,不然只有第一页。

 

step2:运行代码

from bs4 import BeautifulSoup
import xlwt


if __name__ == '__main__':
    workbook = xlwt.Workbook(encoding='utf-8')
    worksheet = workbook.add_sheet('1')
    txt_path="b.txt"

    head = ["公司", "内推", "网申", "笔试", "面试", "offer"]
    for i, sth in enumerate(head):
        worksheet.write(0, i, sth) #写入表头

    f = open(txt_path, 'r', encoding='UTF-8')
    txt = f.read() #读取html

    soup = BeautifulSoup(txt, "html.parser")

    comps = soup.find_all('div', class_="act-company-body")# 每个公司

    for cindex, comp in enumerate(comps):
        name = comp.find_all('h2') #提取公司名
        worksheet.write(cindex + 1, 0, name[0].text)
        times = comp.find_all('span', class_='act-company-time')  #找出各个时间

        for i, time in enumerate(times):
            worksheet.write(cindex + 1, i + 1, time.text)

    workbook.save("schedule.xls")


OVER

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值