【问题标题】:Cannot extract the description and rating while scraping using requests and Beautiful Soup使用 requests 和 Beautiful Soup 抓取时无法提取描述和评级
【发布时间】:2018-12-13 11:48:24
【问题描述】:

我是网络抓取的初学者,我正在抓取这个特定的网页 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))

【问题讨论】:

    标签: python python-3.x web-scraping beautifulsoup


    【解决方案1】:

    改变:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-07
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 2017-08-14
      • 1970-01-01
      • 2017-07-29
      相关资源
      最近更新 更多