pythonwebscraping提供了错误的源代码

pythonwebscraping提供了错误的源代码,python,web-scraping,amazon,urllib2,Python,Web Scraping,Amazon,Urllib2,我想从Amazon中提取一些数据(以下代码中的链接) 这是我的密码: import urllib2 url="http://www.amazon.com/s/ref=sr_nr_n_11?rh=n%3A283155%2Cn%3A%2144258011%2Cn%3A2205237011%2Cp_n_feature_browse-bin%3A2656020011%2Cn%3A173507&bbn=2205237011&sort=titlerank&ie=UTF8&qi

我想从Amazon中提取一些数据(以下代码中的链接)

这是我的密码:

import urllib2
url="http://www.amazon.com/s/ref=sr_nr_n_11?rh=n%3A283155%2Cn%3A%2144258011%2Cn%3A2205237011%2Cp_n_feature_browse-bin%3A2656020011%2Cn%3A173507&bbn=2205237011&sort=titlerank&ie=UTF8&qid=1393984161&rnid=1000"
webpage=urllib2.urlopen(url).read()
doc=open("test.html","w")
doc.write(webpage)
doc.close()

当我打开test.html时,我的页面内容与Internet上的网站不同。

该页面涉及javascript执行

urllib2.urlopen(..).read()
只需读取url内容即可。所以他们是不同的

要获得相同的内容,您需要使用能够处理javascript的库

例如,以下代码使用:


要完成falsetru的回答:

另一个解决方案是使用。它是基于Qt的。安装起来要重得多,所以我也建议Selenium

使用Firefox将在脚本执行时打开它。要使其不在路上,请使用PhantomJS:

apt-get install nodejs  # you get npm, the Node Package Manager
npm install -g phantomjs  # install globally
[…]
driver = webdriver.PhantomJS()

“不同”是什么意思?你不想使用亚马逊的公共API吗?
apt-get install nodejs  # you get npm, the Node Package Manager
npm install -g phantomjs  # install globally
[…]
driver = webdriver.PhantomJS()