Skip to content

Instantly share code, notes, and snippets.

@sajjadmd
Created September 25, 2019 15:43
Show Gist options
  • Select an option

  • Save sajjadmd/393d3ea15dd4c3eb33504bc273d2b663 to your computer and use it in GitHub Desktop.

Select an option

Save sajjadmd/393d3ea15dd4c3eb33504bc273d2b663 to your computer and use it in GitHub Desktop.
SEO script to get top 100 results from Data For SEO API in to a Google Sheet.
(function() {
clear();
const email = prompt("Email?");
const password = prompt("Password?");
const location = prompt("Location?");
const google = prompt("Google Domain?");
const language = prompt("Language?");
const keyword = prompt("Keyword?");
const params = {};
const ID = Math.floor(Math.random() * 300000) + 1;
params[ID] = {
"se_name": google,
"se_language": language,
"loc_name_canonical": location,
"key": keyword,
};
const data = {
data: params,
};
const AUTH = btoa(`${email}:${password}`)
const headers = {
"Content-Type": "application/json",
"Authorization": `Basic ${AUTH}`,
};
fetch("https://api.dataforseo.com/v2/live/srp_tasks_post", {
method: "POST",
headers: headers,
body: JSON.stringify(data)
})
.then(function(response){
return response.json();
})
.then(function(data) {
const result = [];
for (const position of data.results.organic) {
const url = position.result_url;
const pos = position.result_position;
const title = position.result_title;
const description = position.result_snippet;
const bold = position.result_highlighted.join(" | ");
result.push(`${pos}\t"${url}"\t"${title}"\t"${description}"\t"${bold}"`);
}
const content = "position\turl\ttitle\tdescription\tbold\n" + result.join("\n");
console.log(content);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment