Получил пустой список с красивым супом и селеном

https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_return_of_the_king

Я хочу получить ТОМАТОМЕТР и СЧЕТ АУДИТОРИИ с этого сайта, но получил пустой список.

soup = BeautifulSoup(html, 'html.parser')
notices = soup.select('#tomato_meter_link > span.mop-ratings-wrap__percentage')

0
задан QHarr 8 March 2019 в 08:12
поделиться

2 ответа

Ваш код работает хорошо

>>> 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?

0
ответ дан nmb.ten 8 March 2019 в 08:12
поделиться

Вы можете использовать селектор last-child для типа span с родительским классом. Это использует 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)
0
ответ дан QHarr 8 March 2019 в 08:12
поделиться
Другие вопросы по тегам:

Похожие вопросы: