gpt4 book ai didi

python - 使用请求和 Beautiful Soup 进行抓取时无法提取描述和评级

转载 作者:太空宇宙 更新时间:2023-11-04 02:10:50 25 4
gpt4 key购买 nike

我是网络抓取的初学者,我正在抓取这个特定的网页 https://myanimelist.net/anime/394我无法使用请求和 Beautiful Soup 通过我的 python 代码获取描述和评级。该代码适用于上述 url 索引的其他页面。当相同的代码用于其他页面时,无法在我的代码中找到错误。

到目前为止,我在代码方面的进展是:

from bs4 import BeautifulSoup
import requests


url="https://myanimelist.net/anime/394"
source=requests.get(url)
soup=BeautifulSoup(source.content,'lxml')


def info_anime(soup):

#Extracting the name of the anime

anime=soup.find(name="span",attrs={"itemprop":"name"})
name=anime.text
print ("Anime : "+name)

#Extracting the rating

rating=soup.find(name="div",attrs={"class":"fl-l score"})
print ("Rating : "+(rating.text.strip()))


#extracting the description

des=soup.find(name="span",attrs={"itemprop":"description"})
description=des.text
print ("Description : "+description)

#Extracting the Rank

rank=soup.find(name="span",attrs={"class":"numbers ranked"})
print (rank.text)

#Extracting number of episodes

ep=soup.find(name="div",attrs={"class":"spaceit"})
print (ep.text)

print (info_anime(soup))

最佳答案

改变:

soup=BeautifulSoup(source.content,'lxml')

到:

soup=BeautifulSoup(source.content,'html.parser')

当我改变它时,我得到了输出:

Anime : Ai Yori Aoshi: Enishi
Rating : 7.22
Description : Two years after meeting Aoi, Kaoru and gang are still up to their normal habits. Kaoru now in grad school and the tenants being as rowdy as ever what will become of Aoi and Kaoru's love.

Two years has passed since Aoi and Kaoru were freed from the bonds of their families. They continue to live their normal lives with their usual friends in their house.
Ranked #2737

Episodes:
12

None

关于python - 使用请求和 Beautiful Soup 进行抓取时无法提取描述和评级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53761193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com