var page = new WebPage(), testindex = 0, loadInProgress = false;
page.onConsoleMessage = function(msg)
{
console.log(msg);
};
page.onLoadStarted = function()
{
loadInProgress = true;
};
page.onLoadFinished = function()
{
loadInProgress = false;
};
var steps = [
function() {
page.open("http://hogehoge_wordpress.com/wp-login.php");
},
function() {
page.evaluate(function(){
document.getElementById("user_login").value="<user id>";
document.getElementById("user_pass").value="<user pass>";
document.querySelector('*[name="wp-submit"]').click();
});
},
function() {
page.open('http://hogehoge_wordpress.com/wp-admin/post-new.php');
},
function() {
page.evaluate(function() {
document.querySelector('*[name="post_title"]').value='title';
document.querySelector('*[name="content"]').value='contents';
document.querySelector("#publish").click;
var a = document.querySelectorAll("#publish");
var e = document.createEvent('MouseEvents');
e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a[0].dispatchEvent(e);
waitforload = true;
});
},
function() {
page.render('images/LastLoad.png');
}
];
interval = setInterval(function()
{
if (!loadInProgress && typeof steps[testindex] == "function")
{
console.log("step " + (testindex + 1));
steps[testindex]();
page.render("images/step" + (testindex + 1) + ".png");
testindex++;
}
if (typeof steps[testindex] != "function")
{
page.render('images/finalxx.png');
console.log("Scrapping complete...!");
phantom.exit();
}
}, 5000);// JavaScript Document