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__