【发布时间】:2013-11-07 09:20:09
【问题描述】:
不熟悉js和coffeescript,打算用casperjs下载页面,用python解析。但是我发现我下载的页面与我在浏览器中看到的页面不一样——实际上其中的某些部分在页面保存之前还没有加载。我猜原因可能是没有执行 onload 回调。如果我想下载与我在浏览器中看到的页面相同的页面,我应该怎么做?非常感谢!
我的代码(咖啡脚本):
urls =
'jd' : 'http://list.jd.com/652-654-831-0-0-0-0-0-0-0-1-1-1-1-1-72-4137-33.html'
casper = require("casper").create()
process = (urls) ->
casper.start "", ->
@echo "begin to work"
for name, url of urls
casper.thenOpen url, ->
@echo @download url, "#{name}.html"
process(urls)
casper.run()
【问题讨论】:
-
也许你可以跳过中间步骤,直接用 Python 进行屏幕抓取:stackoverflow.com/questions/5272338/…
-
谢谢。看来我找到了原因:浏览器或 casperjs 只是不知道页面何时完全加载。在方法 download() 中,casperjs 将在下载所有 html 文本后保存页面,而不关心 js 的执行。
标签: javascript download coffeescript phantomjs casperjs