Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
javascript
phantomjs
90google_search.js
90google_search.js
page = require('webpage').create(); doSearch = function() { console.log('Searching...'); page.evaluate(function() { $("input[name=q]").val('what is phantomjs'); $("form").trigger('submit'); return true; }); page.render('phantomjs-searching.png'); }; displayResults = function() { console.log('Results...'); page.evaluate(function() { $('h3 a').each(function(i) { console.log([i + 1, $(this).text(), ' // ' + $(this).attr('href')].join(': ')); }); return true; }); page.render('phantomjs-results.png'); }; page.onLoadFinished = function(status) { if (status === 'success') { page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', function() { if (!phantom.state) { doSearch(); phantom.state = 'results'; } else { displayResults(); phantom.exit(); } }); } else { console.log('Connection failed.'); phantom.exit(); } }; page.onConsoleMessage = function(msg) { console.log(msg); }; page.open('http://google.com');
Reload page
Preview
W3C validation
Edit Code
JS Console