【发布时间】:2021-06-25 18:55:17
【问题描述】:
我想从 IMDb 抓取数据。因为beautifulsoup4 不能使用JavaScript,所以我使用html_request。 但是,我的代码随机给出(没有)结果。当我重复相同的代码 10 次时,有时它会起作用,有时它不会。 time.sleep() 没有帮助(我想也许 JS 需要更长的时间来加载)。 为什么会这样以及如何解决?
# from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://www.imdb.com/title/tt4236770/')
# time.sleep(1)
rating_show = r.html.find('.AggregateRatingButton__RatingScore-sc-1il8omz-1')[0] # either works or 'list index out of range' error
rating_show = float(rating_show.text)
rating_show
【问题讨论】:
标签: python web-scraping python-requests-html