Created
July 10, 2013 03:20
-
-
Save mpobrien/5963234 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var base_url = 'https://groups.google.com/forum/'; | |
var forum_url = base_url + '#!forum/'; | |
var topic_url = base_url + '#!topic/'; | |
var group_url = forum_url + 'mongodb-user'; | |
var jquery_min = 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'; | |
var page = require('webpage').create(); | |
page.viewportSize = { width: 1600, height: 1000 }; | |
page.onResourceRequested = function(request) { | |
//console.log('request' + JSON.stringify(request, undefined, 4) ); | |
}; | |
page.onConsoleMessage = function (msg) { | |
console.log(msg); | |
}; | |
var processGroup = function() { | |
console.log('processing group'); | |
var topics = []; | |
var selection = $('table[role=list] tr > td > div a:visible:not(.visited)'); | |
selection.each(function(index, elem){ | |
var sel = $(elem); | |
// mark element as visited | |
sel.addClass('visited') | |
var subject = sel.text(); | |
var href = sel.attr('href'); | |
topics.push({ 'subject': subject, 'href': href }); | |
}); | |
return topics; | |
}; | |
var scrollDown = function(){ | |
var $scrollBox = $("div[role=main] > div > div > div > div > div").last(); | |
$scrollBox.scrollTop($scrollBox.scrollTop() + 3600); | |
} | |
var grabPage = function(){ | |
var topics = page.evaluate(processGroup); | |
topics.map(function(topic) { | |
console.log(topic.subject + " ---> " + topic.href); | |
}); | |
page.evaluate(scrollDown); | |
setTimeout(grabPage, 3000); | |
} | |
page.open(group_url, function(worked) { | |
console.log('opening page'); | |
if (worked !== 'success') { | |
console.log('problem opening page'); | |
} else { | |
page.includeJs(jquery_min, function() { | |
grabPage(); | |
}); | |
}; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment