如何从beautifulsoup中的div中提取标题中的信息?

时间:2018-01-10 18:51:21

标签: python web-scraping beautifulsoup

我试图从屏幕截图中发布的html中提取评级。它嵌入在div下的标题中。以下代码返回“无”

HTML:

from bs4 import BeautifulSoup

html_soup = BeautifulSoup(response.text, 'html.parser')
type(html_soup)

rest_container = html_soup.find_all('div', 
     class_ = 'i-stars i-stars--regular-5 rating-large')

first_rest=rest_container[0]

print (first_rest.text)

Screenshot of HTML

1 个答案:

答案 0 :(得分:2)

您尚未提供足够的元素供我们为您提供任何解决方案。但是,请试一试。只需在脚本中输入url即可。希望它至少能取得你的评价。

from bs4 import BeautifulSoup
import requests

url = "" #input webpage link here
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html5lib')
for rating in soup.select(".rating-large"):
    print(rating.get("title"))