Получил пустой список с красивым супом и селеном - PullRequest
0 голосов
/ 07 марта 2019

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')

Ответы [ 2 ]

1 голос
/ 08 марта 2019

Вы можете использовать селектор 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 голосов
/ 07 марта 2019

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

>>> 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 переменную?

...