我使用PhantomJS填写并提交表格,然后输出生成的页面。事情是,我不知道这件事是否被提交。PhantomJS:提交表格
我打印生成的页面,但它与原始页面相同。我不知道这是因为它重新导向还是我没有提交,或者我需要等待更长的时间或或。在真正的浏览器中,它发送一个GET并接收一个cookie,它在最终收到最终结果 - 飞行数据之前发送更多的GETS。
我复制了这个例子How to submit a form using PhantomJS,使用不同的url和page.evaluate函数。
var page = new WebPage(), testindex = 0, loadInProgress = false;
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
};
var steps = [
function() {
//Load Login Page
page.open("http://www.klm.com/travel/dk_da/index.htm");
},
function() {
//Enter Credentials
page.evaluate(function() {
$("#ebt-origin-place").val("CPH");
$("#ebt-destination-place").val("CDG");
$("#ebt-departure-date").val("1/5/2013");
$("#ebt-return-date").val("10/5/2013");
});
},
function() {
//Login
page.evaluate(function() {
$('#ebt-flightsearch-submit').click() ;
# also tried:
# $('#ebt-flight-searchform').submit();
});
},
function() {
// Output content of page to stdout after form has been submitted
page.evaluate(function() {
console.log(document.querySelectorAll('html')[0].outerHTML);
});
}
];
interval = setInterval(function() {
if (!loadInProgress && typeof steps[testindex] == "function") {
console.log("step " + (testindex + 1));
steps[testindex]();
testindex++;
}
if (typeof steps[testindex] != "function") {
console.log("test complete!");
phantom.exit();
}
}, 50);
您可能想尝试CasperJS - 它可以与Phantom一起使用,使其更友好。 – 2013-03-27 12:05:33
我想事情是,我不确定任何事情都可以用这个页面。就像他们正在积极阻止拼抢企图一样。 PhantomJs是我尝试的第四件事。 – user984003 2013-03-27 12:08:21
使用Casper,在动作之间暂停大约400ms,将User Agent更改为匿名的例如'Mozilla/5.0(Macintosh; Intel Mac OS X 10_8_3)AppleWebKit/536.28.10(KHTML,如Gecko)Version/6.0.3 Safari/536.28.10'(这就像Phantom一样的Webkit,但与任何Safari用户相同在OSX 10.8.3上),如果不起作用,会感到惊讶。 – 2013-03-27 13:14:19