【Python】爬取哔哩哔哩投稿信息

Longli Lv3

通过Python爬取哔哩哔哩稿件信息的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
from lxml import etree

L1 = []
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'}


def getCode():
url = ("http://www.bilibili.com/video/av" + avNo)
code = requests.get(url, headers=headers)
html = etree.HTML(code.text)

# up主名字
texts = html.xpath('//*[@id="v_upinfo"]/div[2]/div[1]/a[1]')

if len(texts) < 1:
up = "none"
else:
for index in range(len(texts)):
if (index % 2) == 0:
up = texts[index].text

# 投稿名字
texts = html.xpath('//*[@id="viewbox_report"]/h1/span')
if len(texts) < 1:
name = "none"
else:
for index in range(len(texts)):
if (index % 2) == 0:
name = texts[index].text

# 投稿时间
texts = html.xpath('//*[@id="v_upinfo"]/div[3]/div/span/span')
if len(texts) < 1:
playnum = "none"
else:
for index in range(len(texts)):
if (index % 2) == 0:
playnum = texts[index].text
print("av:", avNo, "up主:", up, "投稿名:", name,"粉丝数:",playnum)


if __name__ == '__main__':
getCode()

  • 标题: 【Python】爬取哔哩哔哩投稿信息
  • 作者: Longli
  • 创建于 : 2022-01-01 00:00:00
  • 更新于 : 2025-06-23 00:47:22
  • 链接: https://blog.longli.space/2022/01/01/2020010102/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
【Python】爬取哔哩哔哩投稿信息