たまたま、skyscanner は大規模な商用 Web サイトにのみ API を提供しているため、自分の目的 (非商用) で複数の目的地の結果を取得するための小さなアプリケーションを独自に構築したいと考えました。
ページがフライト検索を完了して結果を表示するのに数秒かかるため、フライト検索の結果を取得するのはかなり難しいようです。
wget、lynx、links2、または edbrowse を使用してもうまくいきませんでした。たぶん私は何か間違ったことをしました、私にはわかりません。
しかし、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][5]に記載されているタイムラグがあっても動作しませんでした。スクリプトは (正常に返された場合) スカイスキャナーのエラー ページのみを表示し、問題が発生したことを示します。
説明されているエラーページをもたらした最後の試みは次のとおりです。
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 ベースおよび/またはシェル スクリプト ベースのソリューションを構築しようとしています。