Created
January 26, 2022 16:22
-
-
Save MartMcMahon/563a459b7d52292eba6698cb7d7f4c67 to your computer and use it in GitHub Desktop.
pulling plant dates from alamanac.com
This file contains 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 puppeteer = require("puppeteer"); | |
const main = async (browser) => { | |
let page = await browser.newPage(); | |
await page.goto( | |
"https://www.almanac.com/gardening/planting-calendar/zipcode/78741" | |
); | |
await page.waitForSelector("#seed-start-dates-table"); | |
const rows = await page.evaluate(() => | |
Array.from(document.querySelectorAll(".plantrow"), (el) => { | |
let dates = Array.from(el.querySelectorAll("td"), (el) => el.textContent); | |
let stuff = {}; | |
let plantName = el.querySelector("th").textContent; | |
stuff.name = plantName; | |
stuff.dates = dates; | |
return stuff; | |
}) | |
); | |
let plants = rows.map((plant) => { | |
console.log(plant); | |
return plant; | |
}); | |
browser.close(); | |
}; | |
puppeteer.launch().then(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment