这是网站..。
右击页面中间的标题“检查”招贴画会显示代码。从教程到帖子,我尝试了太多的变体。这就是我的Python脚本..。
import requests
from bs4 import BeautifulSoup
url = "https://www.rottentomatoes.com/browse/dvd-top-rentals/?services=amazon;amazon_prime;fandango_now;hbo_go;itunes;netflix_iw;vudu"
r = requests.get(url)
soup = BeautifulSoup(r.content, "lxml")下一步?
发布于 2017-01-24 03:57:22
此页面由JavaScript呈现,requests只返回html代码:

真正的数据在这个网址中:
https://www.rottentomatoes.com/api/private/v2.0/browse?page=1&limit=30&type=dvd-top-rentals&services=amazon%3Bamazon_prime%3Bfandango_now%3Bhbo_go%3Bitunes%3Bnetflix_iw%3Bvudu&sortBy=popularity代码:
import requests
r = requests.get('https://www.rottentomatoes.com/api/private/v2.0/browse?page=1&limit=30&type=dvd-top-rentals&services=amazon%3Bamazon_prime%3Bfandango_now%3Bhbo_go%3Bitunes%3Bnetflix_iw%3Bvudu&sortBy=popularity')
data = r.json()
for result in data["results"]:
print(result["title"], result["tomatoScore"])退出:
The Girl on the Train 43
Keeping Up With The Joneses 19
Ouija: Origin of Evil 82
Long Way North (Tout en haut du monde) 98
The Whole Truth 29
Come And Find Me 67
LEGO Jurassic World: The Indominus Escape None
My Father, Die 88
When Elephants Were Young None
Roger Corman's Death Race 2050 None
Take the 10 None
Deepwater Horizon 83
The Accountant 51
The Birth of a Nation 72
Kevin Hart: What Now? 76答:
当您需要抓取网站时,只需禁用浏览器中的JavaScript,检查页面内容是否已更改。

我在chrome中使用这个扩展名,只需单击一下就可以禁用JS。

使用chrome开发工具的网络监控网络活动,即使页面使用JS获取数据,它仍然需要向服务器发出请求,您可以在网络选项卡中找到这些请求。
u''是python2中unicode的表示,它在python3中的默认设置。它只显示在python中,不需要担心它。https://stackoverflow.com/questions/41819726
复制相似问题