鸿 鸿 2023-07-26 20:04 采纳率: 92.7%
浏览 5

不能翻页获取视频,咋改啊

import requests
from lxml import etree

headers = {
    'authority': 'ibaotu.com',
    'pragma': 'no-cache',
    'cache-control': 'no-cache',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
    'accept': '*/*',
    'origin': 'https://plus.ibaotu.com',
    'sec-fetch-site': 'same-site',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://plus.ibaotu.com/search?category=%E8%A7%86%E9%A2%91&keyword=',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'cookie': 'md_session_id=20230719003256124; user_refers=a%3A2%3A%7Bi%3A0%3Bs%3A3%3A%22bwd%22%3Bi%3A1%3Bs%3A13%3A%22www.baidu.com%22%3B%7D; new_edition_type_v4=1; __is_small_screen=1; Hm_lvt_4df399c02bb6b34a5681f739d57787ee=1689776260; Hm_lpvt_4df399c02bb6b34a5681f739d57787ee=1689776260; md_session_expire=1800; FIRSTVISITED=1689776264.704; from_type=; referer=http%3A%2F%2Fibaotu.com%2F%3Fm%3DAjaxSearch%26a%3Ddef; _clck=epszo2|2|fdf|0|1295; _clsk=1kodr2i|1689777324327|5|1|y.clarity.ms/collect',
}
params = {
    'm': 'PlusApi',
    'a': 'search',
    'keyword': '',
    'tabname': '视频',
    'c1': '',
    'c2': '',
    'c3': '',
    'c4': '',
    'format_type': '',
    'width': '',
    'height': '',
    'copyright': '',
    'resolution': '',
    'duration': '',
    'page': '3',
    'size': '80',
    'sort': '',
    'format': '',
    'color': '',
}

response = requests.get(url=f'https://ibaotu.com/shipin/7-0-0-0-0-1.html', headers=headers)  # 发送请求

html_text = response.content.decode('utf-8')  # 编译

html = etree.HTML(html_text)  # 自动修正html文档

src_list = html.xpath('//div[@class="video-play"]/video/@src')  # 视频网址

title_list = html.xpath('//span[@class="video-title"]/text()')  # 视频名称
for src, title in zip(src_list, title_list):
    res = requests.get('https:' + src, headers=headers)
    filename = title + '.mp4'
    print('正在下载视频:' + filename)
    with open('video/' + filename, 'wb') as f:
        f.write(res.content)

请问怎么实现翻页获取多页视频,

img

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-07-26 22:20
    关注

    怀疑你的问题是 f.write 没有使用追加模式,每次把上一次写入的冲掉了
    你调试下

    评论

报告相同问题?

问题事件

  • 创建了问题 7月26日

悬赏问题

  • ¥15 求帮生成一个lattice diamond的许可证
  • ¥15 大一前端新生求教学解答
  • ¥15 如何制作一个可以查看“网游有序列的装备词条”的软件/插件
  • ¥15 CS2打5E与完美天梯匹配会与服务器断开连接(黑框没标明具体原因)
  • ¥15 利用cst反推材料电磁参数,推出想x,y,z方向的相对介电常数与磁导率
  • ¥15 求帮助!用赛灵思FPGA XC7A35T对一个频率50MHz的数字信号读取高低电平,只用HR bank普通单端io进行采样可以吗
  • ¥15 训练准确率100%,测试准确率只有50%
  • ¥15 grafana创建dashhabord提示no data sources of type Prometheus Alert
  • ¥15 python用arima时间序列法预测不出结果 急
  • ¥15 思科交换机如何恢复配置