不是,爬虫入门这么简单?

import requests
from bs4 import BeautifulSoup
head = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0)"
}
a = requests.get(
    "https://www.bilibili.com/video/BV1d54y1g7db?p=10&spm_id_from=pageDriver&vd_source=4b62b589d54700fc1e9e195f35940c15", headers=head)
print(a.status_code)
if a.ok:
    b = BeautifulSoup(a.text, "html.parser")
    c = b.findAll("div", attrs={"class": "info"})
    for item in c:
        d = item.findAll("a")
        for e in d:
            f = e.findAll("p")
            for o in f:
                print(o.string)
else:
    print("114514")

发表评论