Last active
March 17, 2023 21:14
-
-
Save spencerkittleson/5a098baa1319563d406831a973f0888c to your computer and use it in GitHub Desktop.
Bot to get titles
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
import puppeteer from "puppeteer"; | |
(async () => { | |
const browser = await puppeteer.launch({ headless: false }); | |
const page = await browser.newPage(); | |
await page.goto( | |
"https://sfbay.craigslist.org/search/sby/sof#search=1~thumb~0~0" | |
); | |
// Set screen size | |
await page.setViewport({ width: 1080, height: 1024 }); | |
// Wait and click on first result | |
const searchResultSelector = ".titlestring"; | |
await page.waitForSelector(searchResultSelector); | |
// https://github.com/puppeteer/puppeteer/issues/3713#issuecomment-452929764 | |
const titleLinks = await page.$$(searchResultSelector); | |
for (const titleLink of titleLinks) { | |
const text = await titleLink.evaluate((el) => el.textContent); | |
const href = await titleLink.evaluate((el) => el.href); | |
if (text.indexOf("Python") != -1) { | |
console.log(href); | |
} | |
} | |
await browser.close(); | |
})(); |
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
{ | |
"name": "botclist", | |
"version": "1.0.0", | |
"description": "", | |
"type": "module", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"puppeteer": "^19.7.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment