Skip to content

Instantly share code, notes, and snippets.

@son0fhobs
Last active August 29, 2015 13:57
Show Gist options
  • Save son0fhobs/9459324 to your computer and use it in GitHub Desktop.
Save son0fhobs/9459324 to your computer and use it in GitHub Desktop.
Scrape SEO Quake Results, convert to JSON
<h3>Json</h3>
<textarea id="seoquake-csv-output"></textarea>
<div id="serp_csv"></div>
<hr />
<div id="json"></div>
/* THIS NEEDS TO BE MODIFIED TO ACTUALLY RUN IN SERPS */
/*
// It requires seoquake extension to be ready, and it still needs to import jquery in no conflict to work. This is for testing currently.
*/
// appending 2 csv - split(/\r\n/), loop through arrays adding lines, then join('\r\n');
var seo_quake_val = '"Url";"Google pagerank";"Google index";"SEMrush links";"SEMrush linkdomain";"Bing index";"Alexa rank";"Webarchive age";"Whois";"Page source";"SEMrush Rank"\r\n"http://www.fourthchurch.org/";"4";"4,130";"385";"938";"n/a";"1687507";"December 1, 1998";"whois";"source";"n/a"\r\n"http://www.chicagopresbytery.org/church-list/";"2";"4,020";"1";"442";"n/a";"n/a";"October 13, 1999";"whois";"source";"n/a"\r\n"http://www.chicagopresbytery.org/";"4";"4,020";"308";"442";"n/a";"n/a";"October 13, 1999";"whois";"source";"n/a"\r\n"http://www.covenantchicago.org/";"3";"57";"147";"158";"n/a";"n/a";"April 29, 2001";"whois";"source";"n/a"\r\n"http://en.wikipedia.org/wiki/Fourth_Presbyterian_Church_(Chicago)";"0";"28,400,000";"6";"133528830";"n/a";"6";"November 27, 2002";"whois";"source";"n/a"\r\n"http://www.yelp.com/biz/fourth-presbyterian-church-chicago-2";"3";"9,740,000";"50";"5115324";"n/a";"140";"November 28, 1996";"whois";"source";"n/a"\r\n"http://www.lakeviewpresbyterian.org/";"3";"222";"281";"366";"n/a";"13091376";"September 25, 2002";"whois";"source";"n/a"\r\n"http://lincolnsquarepres.org/";"2";"102";"4";"95";"n/a";"n/a";"January 24, 2010";"whois";"source";"1288243"\r\n"http://lppchurch.org/";"2";"77";"1";"1";"n/a";"n/a";"August 9, 2002";"whois";"source";"2176115"\r\n"http://2ndpresbyterian.org/arthistory/";"2";"348";"3";"227";"n/a";"15105401";"October 17, 2000";"whois";"source";"2146838"';
$('#seoquake-csv-output').val(seo_quake_val);
seo_quake_val = $('#seoquake-csv-output').val();
var split_csv = seo_quake_val.split(/\"\s+\"/);
// console.log(split_csv);
// $('#serp_csv').html(seo_quake_val);
var serp_csv = seo_quake_val.replace(/\"/ig, " ");
var serp_csv = serp_csv.replace(/\s;/ig, ", ");
// var serp_csv = serp_csv.replace(/\\r\\n/ig, "\r\n");
var split_csv = serp_csv.split("\n");
serp_json_str = csvJSON(serp_csv);
// $('#serp_csv').html(serp_csv);
serp_json = $.parseJSON(serp_json_str);
console.log($.parseJSON(serp_json));
$('#json').html(serp_json_str);
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
var obj = {};
var currentline=lines[i].split(",");
for(var j=0;j<headers.length;j++){
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
//return result; //JavaScript object
return JSON.stringify(result); //JSON
}
/*
// var serp_json = csvJSON(csv);
// $('#json').html(serp_json);
// $('#json').html('json goes here');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment