鱼C论坛

 找回密码
 立即注册
查看: 1851|回复: 2

[作品展示] 批量爬取梨视频(基础版)

[复制链接]
发表于 2020-8-1 11:52:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

批量下载小视频,不到40行代码
没有添加函数,因为我是小白
应该大部分的鱼油都能看懂,路过的朋友给个支持呗




  1. import requests
  2. import parsel



  3. headers = {
  4.     'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3760.400 QQBrowser/10.5.4083.400'
  5. }
  6. target = "https://www.pearvideo.com/"
  7. page = 1
  8. for i in range(10,50,10):
  9.     print("====================开始下载第%d页==========================="%page)
  10.     page += 1
  11.     url = "https://www.pearvideo.com/popular_loading.jsp?reqType=1&categoryId=8&start={}".format(i)
  12.     res = requests.get(url,headers=headers)
  13.     res.encoding="utf-8"
  14.     html = parsel.Selector(res.text)
  15.     lists = html.xpath('//li/a/@href').getall()
  16.     for each in lists:
  17.         links = target + each
  18.         print("下载链接为:",links)
  19.         response = requests.get(url=links,headers=headers)
  20.         response.encoding="utf-8"
  21.         htmls = parsel.Selector(response.text)
  22.         content = htmls.re('srcUrl="(.*?)",vdoUrl=')
  23.         name = htmls.re('<title>(.*?)-梨视频官网-Pear Video</title>')
  24.         #print("开始下载视频:",name)
  25.         for names in name:
  26.             
  27.             for video in content:
  28.                 #vs = video.split("/")[-1]
  29.                 videos = requests.get(url=video,headers=headers)

  30.                 f_name = names + ".mp4"
  31.                 with open(str(f_name),"wb") as f:
  32.                     f.write(videos.content)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-8-1 13:13:41 | 显示全部楼层
居然沉了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-1 13:20:52 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-24 16:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表