2
私はPhantomJSを使って簡単なフォームから結果を得ようとしています。私はjQueryを使用していますが、動作しません。PhantomJSで送信フォームを送信した後の結果の入手方法は?
<!doctype html>
<html>
<head>
<title>PhantomJS!</title>
</head>
<body>
<form method="post" id="frm">
<input type="text" name="nombre" id="nombre" />
<input type="submit" value="Publicar" id="btn-submit" />
</form>
Your name is <span id="nombrez"><?php if (isset($_POST['nombre'])) { echo $_POST['nombre'];} ?></span>
</body>
</html>
そして、このJavascriptコード:
var page = require('webpage').create();
page.open('http://localhost/phantom/', function() {
page.includeJs("https://code.jquery.com/jquery-3.1.1.slim.js", function() {
page.evaluate(function() {
$('#nombre').val('Fabian');
document.forms[0].submit();
});
page.onLoadFinished = function(){
console.log($("#nombrez").html());
phantom.exit();
};
});
});
ありがとうございました。私はちょうどあなたのコードにこれを加えて、それは動作しますか: if(html!= ""){console.log(html); phantom.exit();} –