传智播客视频python视频爬虫

使用步骤

1.引入库

代码如下(示例):

from selenium import webdriver
from time import sleep
import os
import requests

2.读入数据

代码如下(示例):

def get_urls(index1, index2):
    base_url = "https://new-bxgstorge.boxuegu.com/bxg/textbook/052/afterClassVideo/052"
    p=q=''
    if len(index1) == 1:
        p = "00"+index1
    else:
        p = "0"+index1
    if len(index2) == 1:
        q = '00'+index2
    else:
        q = '0'+index2
    url = base_url+p+q+'.mp4'
    return url


def get_dir(url):
    option = webdriver.ChromeOptions()
    # option.add_argument('headless')
    browser = webdriver.Chrome(chrome_options=optionyuy
    browser.get(url)
    sleep(3)
    chapters = browser.find_elements_by_xpath("//div[@class='video-directory-content']"
                                              "/div[@id='chapterPointsBox']/div[@class='el-scrollbar']"
                                              "/div[@class='el-scrollbar__wrap']/div[@class='el-scrollbar__view']"
                                              "/div[@class='chapter-item-box expand']")
    for index1, c in enumerate(chapters):
        chapt_name = c.find_element_by_xpath("div[@class='chapter-text ellipsis']/span[2]").text
        path = "F:\\video\\" + chapt_name
        if not os.path.exists(path):
            os.makedirs(path)
        dchapt_names = c.find_elements_by_xpath("div[@class='points-box']/div[contains(@class,'point-item-box')]/"
                                                "span[@class='point-text-box']/span[@class='point-text ellipsis']")
        for index2, dchapt_name in enumerate(dchapt_names):
            mv_path = path+"\\"+str(index2+1)+'、'+dchapt_name.text.replace('<','p').replace('>', 'p')+'.mp4'
            print(mv_path)
            url = get_urls(str(index1+1),str(index2+1))
            print(url)
            # try:
            if  not os.path.exists(mv_path):
                resp = requests.get(url)
                sleep(3)
                with open(mv_path, 'wb') as f:
                    f.write(resp.content)
                    f.close()
                    print("success")
            else:
                print('文件已经存在')
            # except:
            #     print("爬取失败")
# https://new-bxgstorge.boxuegu.com/bxg/textbook/052/afterClassVideo/052001001.mp4
url = "http://tch.ityxb.com/video/6aa88b8193be49c3b8bef9910058b0ca/c1333acbfda346489af0f7488d9a0e2b/adcbc40cb73e4d229ed199da1742bd8f"
get_dir(url)

该处使用的url网络请求的数据。


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunnuan01

一起学习,共同进步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值