scrapePostsProductForums.js

"use strict"; function waitFor(testFx, onReady, timeOutMillis) { var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, //< Default Max Timout is 3s start = new Date().getTime(), condition = false, interval = setInterval(function() { if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) { condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code } else { if(!condition) { phantom.exit(1); } else { typeof(onReady) === "string" ? eval(onReady) : onReady(); clearInterval(interval); } } }, 250); }; // This is where the magic starts var url = 'https://productforums.google.com/forum/#!profile/youtube/APn2wQfyTyuz6gxoyO2o6xTtMqAgQP59DqH9lLHtew5nO1TR_WxS2EmCDHwIZht_nGQrIGKTdOM6'; // Link to your profile var page = require('webpage').create(); page.open(url, function (status) { // Check for page load success if (status !== "success") { console.log("Oops"); } else { page.includeJs("https://code.jquery.com/jquery-1.12.0.min.js"); // Hi jQuery waitFor(function() { return page.evaluate(function() { return jQuery(".NUXPAI-x-b").is(":visible"); // Is the graph there yet? }); }, function() { var postsLastMonth = page.evaluate(function() { return jQuery('.gwt-viz-container table tbody tr:last td:last').text() }); // Thats where the posts are console.log(postsLastMonth); phantom.exit(); }); } });
Grab your latest post count from the Google Product Forums using PhantomJS

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.