2024-10-03 04:29:15 发布
网友
https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_return_of_the_king
我想从那个网站上得到Tometer和观众评分, 但名单是空的
soup = BeautifulSoup(html, 'html.parser') notices = soup.select('#tomato_meter_link > span.mop-ratings-wrap__percentage')
你的代码运行得很好
>>> from bs4 import BeautifulSoup >>> html = requests.get('https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_return_of_the_king').text >>> soup = BeautifulSoup(html, 'html.parser') >>> notices = soup.select('#tomato_meter_link > span.mop-ratings-wrap__percentage') >>> notices [<span class="mop-ratings-wrap__percentage">93%</span>]
你是怎么得到html变量的
html
可以将跨度类型的最后一个子选择器与父类一起使用。这是使用BeautifulSoup 4.7.1
import requests from bs4 import BeautifulSoup res = requests.get('https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_return_of_the_king') soup = bs(res.content, 'lxml') ratings = [item.text.strip() for item in soup.select('h1.mop-ratings-wrap__score span:last-child')] print(ratings)
你的代码运行得很好
你是怎么得到
html
变量的可以将跨度类型的最后一个子选择器与父类一起使用。这是使用BeautifulSoup 4.7.1
相关问题 更多 >
编程相关推荐