Created
July 25, 2018 10:55
-
-
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.
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
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