1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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 |
Script sample to posting to wordpress by phantomjs.