Skip to content

Instantly share code, notes, and snippets.

@joegaffey
Created July 25, 2018 10:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegaffey/0d856c9449999999c2f0263ed2566953 to your computer and use it in GitHub Desktop.
Save joegaffey/0d856c9449999999c2f0263ed2566953 to your computer and use it in GitHub Desktop.
Simple scraper snippet. Paste it into the console of a page with a list of links where you want to pull specific items from each link. Change selector consts according to your needs.
const linksSelector = '.link-selector';
const itemSelectors = ['.item1', '.item1', '.item1'];
const anchors = document.querySelectorAll(linksSelector);
const links = [];
anchors.forEach((anchor) => { links.push(anchor.href) });
const results = [];
links.forEach((link) => {
fetch(link)
.then(function(response) {
return response.text();
})
.then(function(text) {
let el = document.createElement('html');
el.innerHTML = text;
let row = [];
itemSelectors.forEach((itemSelector) => {
let targetEl = el.querySelector(itemSelector)
if(targetEl)
row.push({Name: itemSelector, Value: targetEl.textContent});
});
console.table(row);
results.push(row);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment