parent
78771220b3
commit
afb32c8ff1
@ -1,29 +0,0 @@
|
||||
import requests
|
||||
import json
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
|
||||
|
||||
def bvid2cid(bvid): # 获取视频cid
|
||||
url = "https://api.bilibili.com/x/player/pagelist?bvid=" + str(bvid) + "&jsonp=jsonp"
|
||||
r = requests.get(url)
|
||||
dirt = json.loads(r.text)
|
||||
cid = dirt['data'][0]['cid']
|
||||
return cid
|
||||
|
||||
|
||||
def cid2data(cid):
|
||||
url = 'https://api.bilibili.com/x/v1/dm/list.so?oid=' + str(cid)
|
||||
r = requests.get(url=url)
|
||||
r.encoding = 'utf-8'
|
||||
html = BeautifulSoup(r.text, 'html5lib')
|
||||
ds = html.find_all('d')
|
||||
said = '.*">(.*)</d>.*'
|
||||
for d in ds:
|
||||
with open(str(cid) + '.txt', 'a', encoding='utf-8') as f:
|
||||
f.write(re.findall(said, str(d))[0] + '\n')
|
||||
|
||||
|
||||
cid = bvid2cid('BV1gp4y1e7cE')
|
||||
cid2data(cid)
|
||||
|
Binary file not shown.
Loading…
Reference in new issue