吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2574|回复: 14
收起左侧

[Python 转载] 某视频网站抓取排行榜视频

[复制链接]
aiyamaya 发表于 2022-5-5 18:13
程序默认下载目录为D盘根目录,请指正

[Python] 纯文本查看 复制代码
import requests
from lxml import etree
import time

url ='https://www.pearvideo.com/popular'
raw_url = 'https://www.pearvideo.com/'

respon = requests.get(url)
main_page = etree.HTML(respon.text)
name_list = main_page.xpath("/html/body/div[2]/div/div[1]/ul")

for i in name_list:  # 各个榜单的名字和代码
    pop_name = i.xpath("./li/a/text()")
    print('榜单为:',pop_name)
    pop_num = i.xpath("./li/a/@href")
    # print(pop_num)
    

input_name = input('输入榜单名称:')
if input_name in pop_name:
    pop_page_url = raw_url+pop_num[pop_name.index(input_name)]
else:
    pop_page_url = url
    print('将使用默认总榜!')

respon = requests.get(pop_page_url)
top_page = etree.HTML(respon.text)
top_list = top_page.xpath('//*[@id="popularList"]')
for j in top_list:  # 榜单的视频id
    vedio_id = j.xpath("./li/div/div/span/@data-id")
    file_name = j.xpath('./li/div/a/h2/text()')

for k in vedio_id:
    url = f'https://www.pearvideo.com/video_{k}'
    XHR_url = f'https://www.pearvideo.com/videoStatus.jsp?contId={k}&mrd=0.12841592667885604'

    head = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0',
            'Referer':url}
    respon = requests.get(XHR_url,headers=head)
    systemTime = respon.json()['systemTime']
    srcUrl = respon.json()['videoInfo']['videos']['srcUrl']
    srcUrl = srcUrl.replace(systemTime,f'cont-{k}')
    output_name = file_name[vedio_id.index(k)]
    f = open(f'd:/{output_name}.mp4',mode='wb')
    f.write(requests.get(srcUrl).content)
    f.close()
    print(output_name,'下载完毕!')
    time.sleep(2)

respon.close()

免费评分

参与人数 4吾爱币 +4 热心值 +4 收起 理由
minblack3 + 1 + 1 我很赞同!
fengshengshou + 1 + 1 谢谢@Thanks!
sssguo + 1 + 1 我很赞同!
日月与你 + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

wangjj5741 发表于 2022-5-5 21:14
我不懂,进来看一下
nihaohello1 发表于 2022-5-5 21:42
周师傅 发表于 2022-5-5 22:19
ych13846701169 发表于 2022-5-5 22:31
了解了,谢谢分享
xi0729 发表于 2022-5-5 22:50
必须给个赞
lengyanwl 发表于 2022-5-5 23:02
看看~感谢分享
xingwenzhiyuan 发表于 2022-5-6 06:40
进来学习一下,谢谢你的分享
cy2931 发表于 2022-5-6 11:00
学习一下
basovusr 发表于 2022-5-16 16:57
感谢分享,学习了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 05:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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