daobalong 2021-02-18 00:12 采纳率: 80%
浏览 180
已采纳

想给家里老人爬取些广场舞的视频,遇到问题,求大神指导

打算先爬取视频内容合集页大概100左右数量的单个视频页的地址,再转到单个视频页爬取视频,但是返回的结果是空值,试过其他几种定位方式,都不行

import requests

from bs4 import BeautifulSoup

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
    'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Encoding' : 'gzip',
    'DNT' : '1', 
    'Connection' : 'close',
    'Accept-Language':'zh-CN'
}
f
url_address = 'https://haokan.baidu.com/author/1622522456467855'  
item_collection_responde = requests.get(url = url_address, headers = headers)
item_collection_soup = BeautifulSoup(item_collection_responde.content,  'lxml')
item_collection =  item_collection_soup.find_all('a', class_= 'card-item-link skeleton')

print(item_collection)

也试过第二步,直接在单个视频页抓取 <video>标签里的下载地址,也是返回空值

  • 写回答

6条回答 默认 最新

  • 天际的海浪 2021-02-20 15:27
    关注

    我又研究了一下,发现可以直接爬取好看视频网站的json数据

     

    import requests
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
        'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Encoding' : 'gzip',
        'DNT' : '1',
        'Connection' : 'close',
        'Accept-Language':'zh-CN'
    }
    
    url_address = 'https://haokan.baidu.com/author/1622522456467855'
    
    ctime = ""
    while True:
        resjson = requests.get(url = f'{url_address}?_format=json&rn=16&ctime={ctime}&_api=1', headers = headers).json()
        response = resjson['data']['response']
        for it in response['results']:
            print("视频名称:",it['content']['title'])
            print("标清视频地址:",it['content']['video_list'].get('sd','无'))
            print("高清视频地址:",it['content']['video_list'].get('hd','无'))
            print("超清视频地址:",it['content']['video_list'].get('sc','无'))
            print()
        if response['has_more'] == 0:
            print("爬取结束")
            break
        ctime = response['ctime']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?