I'm trying to capture the username of each user on the page.I've tried about 5 different CSS Selector inputs for the itemArea variable. I think I'm just not experienced enough with css or html....
If anyone knows how to grab that info, and could link a resource for specific navigation on html or css for this usage that would be very helpful.
New to javascript, and this program is infinitely easier in python, but i'd like to see this project through.
const puppeteer = require('puppeteer');
const url = "https://poshmark.com/category/Men-Jackets_&_Coats?sort_by=like_count&all_size=true&my_size=false";
let usernames = [];
async function main() {
const client = await puppeteer.launch({
headless: true,
executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
});
const page = await client.newPage();
await page.goto(url);
await page.waitForSelector(".tc--g.m--l--1.ellipses");
const itemArea = await page.evaluate(() => {
Array.from(document.querySelectorAll('.tc--g m--l--1 ellipses' )).map(x => x.textContent());
console.log(itemArea);
});
itemArea.each(function (i, element) {
//console.log('username: ', $(element).text());
usernames.push($(element).text());
console.log(usernames);
});
};
main();
Tried many different css inputs for a few hours, my main errors i get are:
Reference Error, itemArea is not defined CSS Selector is incorrect Evaluation failed: TypeError: x.textContent is not a function
FYI, the first text im trying to grab on that page is ishhbang. That is his username. After that my plan is to write a loop to get all usernames.
I got this to work in Cheerio using this code:
let res = await axios.get(url);
let $ = await cheerio.load(res.data);
const itemArea = $(".tiles_container a.tile__creator span");
In puppeteer that returns Evaluation failed: TypeError: x.textContent is not a function
Thanks a lot to anyone who helps.