Here at first I login to linkedin and create else one tab which I can open the linkedin link I am taking from incubators json looks like; [{linkeding: "url"}],
And I need put them to Array.from()
but there said:
Error: Evaluation failed: ReferenceError: json is not defined
How I can fix this
const puppeteer = require("puppeteer");
const json = require("./../incubators.json");
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto("https://www.linkedin.com/");
await page.type("#session_key", "gamerlex2004@gmail.com");
await page.type("#session_password", "bakai987");
await Promise.all([
page.click(
"#main-content > section.section.hero > div > div > form > button"
),
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
const page2 = await browser.newPage();
await page2.setViewport({ width: 1200, height: 720 });
const urls = await page2.evaluate(() =>
Array.from(json, (element) => element.linkedin_url)
);
for (let i = 0, total_urls = urls.length; i < total_urls; i++) {
await page2.goto(urls[i]);
await page2
.evaluate(async () => {
let data = [];
let elements = document.querySelectorAll(
"body > div.application-outlet > div.authentication-outlet > div > div.scaffold-layout.scaffold-layout--breakpoint-xl.scaffold-layout--main-aside.scaffold-layout--reflow > div"
);
for (const element of elements) {
data.push({
linkedinUrl: page2.url().toString() || "",
linkedinProfileUrl:
element.querySelector("#ember45")?.getAttribute("src") || "",
});
}
return data; // Return our data array
})
.then((data) => {
fs.appendFile("./image.json", JSON.stringify(data), (err) =>
err ? console.log(err) : null
);
});
}
})();