由于skyscanner只为大型商业网站提供api,我想自己构建一个小应用程序,为我自己的目的(非商业)检索多个目的地的结果。
我发现获取航班搜索结果似乎相当困难,因为页面需要几秒钟才能完成航班搜索并显示结果。
使用wget、lynx、links2或edbrowse对我不起作用,因为我得到的结果是我的浏览器没有启用javascript,即使links2是在支持javascript的情况下编译的。也许我做错了什么,我不知道。
但是,到目前为止,phantomjs提供了最大的努力,我尝试了多个代码片段来检索航班搜索结果。
来源:
[Stackoverflow#1][1]
[Stackoverflow#2][2]
[Techslides][3]
[Stackoverflow#3][4]
[Stackoverflow#4][5]
[1]: http://stackoverflow.com/questions/18526140/how-to-get-html-generated-from-javascript-using-phantomjs
[2]: http://stackoverflow.com/questions/28209509/get-javascript-rendered-html-source-using-phantomjs
[3]: http://techslides.com/grabbing-html-source-code-with-phantomjs-or-casperjs
[4]: http://stackoverflow.com/questions/12450868/how-to-print-html-source-to-console-with-phantomjs
[5]: http://stackoverflow.com/questions/8692038/phantomjs-page-dump-script-issue即使在Stackoverflow#4中描述的时间延迟,它也不起作用。这些脚本(在成功返回的情况下)只显示skyscanner的错误页面,说明它们遇到了问题。
我尝试的最后一次尝试导致了描述的错误页面是:
var page = new WebPage(),t, address;
var fs = require('fs');
var url = 'http://www.skyscanner.at/transport/fluge/nyca/lax/150626/150627/flugpreise-von-new-york-nach-los-angeles-international-im-juni-2015.html?adults=1&children=0&infants=0&cabinclass=economy&rtn=1&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false';
address = encodeURI(url);
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
f = null;
var markup = page.content;
console.log(markup);
try {
f = fs.open('htmlcode.txt', "w");
f.write(markup);
f.close();
} catch (e) {
console.log(e);
}
}
phantom.exit();
});以前有没有人尝试过这样的东西,并且成功了?你是怎么让它工作的?我正在尝试在一个没有gui的Debian-Linux系统上构建一个基于php和/或shell脚本的解决方案。
发布于 2015-07-02 18:24:37
我在Skyscanner做工程工作。这不是你问题的答案,但是,如果你最终出现在那个错误页面(或验证码页面),很可能是我们的机器人拦截器抓住了你。这是一种“设计出来的”:)
我可以给你一个API密钥,有一个保守的速率限制。你会感兴趣吗?
干杯,
Iain
https://stackoverflow.com/questions/30800261
复制相似问题