爬取视频专栏每集名称与时长
import requests
import pandas as pd
url = 'https://api.bilibili.com/x/player/pagelist?bvid=BV12b411K7Zu&jsonp=jsonp'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 '
'Safari/537.36 '
}
res = requests.get(url=url, headers=headers).json()['data']
print(res)
df = pd.DataFrame(columns=['集名', '时长/秒'])
for row in res:
df = pd.concat([df, pd.DataFrame({
'集名': ['P' + str(row['page']) + ' ' + row['part']],
'时长/秒': [row['duration']]
})], ignore_index=True)
df.to_excel('B站视频集名与时长.xlsx')