Невозможно извлечь описание и рейтинг при очистке с использованием запросов и Beautiful Soup - PullRequest
0 голосов
/ 13 декабря 2018

Я новичок в изучении веб-страниц, я просматривал эту конкретную веб-страницу https://myanimelist.net/anime/394, где мне не удалось получить описание и оценку, хотя мой код Python использует запросы и Beautiful Soup.Код работает нормально для других страниц вышеуказанных 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))

1 Ответ

0 голосов
/ 13 декабря 2018

изменить:

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...