bilibili 根据up主下载其下的投稿

本文介绍了如何使用Python爬虫获取B站UP主的所有投稿视频URL,并详细说明了实现过程,包括确定视频个数和AV地址。通过实例展示了针对特定UP主的爬取结果。
摘要由CSDN通过智能技术生成

1 下载模块:

#!/usr/bin/env python

import requests
import json
import time
import re
import hashlib
import os
from get_headers import get_ua # 自己的ua池
# 通用下载函数
def get_content(url,refer = None,params = None):
    headers = {
        'User-Agent':get_ua().encode('utf-8'),
        'Referer':url,
        'Connection':'keep-alive'
    }
    if refer:
        headers['Referer'] = refer

    try:
        response = requests.get(url,headers = headers,params = params)
        time.sleep(1)
        status_code = response.status_code
        if status_code == 200 or status_code == 302:
            return response
        else:
            print ('___status code is %d ___'%status_code)
            exit()
    except Exception as error:
        print ('___get_content is failed___')
        exit()


class DownloadByUrl(object):

    '''this class just for download and save api moves another class'''
    # 只是根据url下载视频,且视频局限于普通视频,不包括番剧
    api_url = 'http://interface.bilibili.com/playurl?'
    fmt2qlt = dict(hdflv=4, flv=3, hdmp4=2, mp4=1)

    SEC1 = '1c15888dc316e05a15fdd0a02ed6584f'
    url = ''
    dan_base = 'https://comment.bilibili.com/{}.xml'

    def __init__
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值