add test file
This commit is contained in:
parent
8860bcecc6
commit
0bae970ff0
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@ linkedout.exe
|
||||
linkedout-macos
|
||||
zip*
|
||||
*.7z
|
||||
*obfuscated.js
|
||||
*obfuscated.js
|
||||
.history
|
||||
43
linkedout.js
43
linkedout.js
@ -29,7 +29,7 @@
|
||||
* Example:
|
||||
* node linkedout.js --headless=true --keyword=layoff
|
||||
*/
|
||||
process.env.PLAYWRIGHT_BROWSERS_PATH = '0';
|
||||
process.env.PLAYWRIGHT_BROWSERS_PATH = "0";
|
||||
|
||||
const { chromium } = require("playwright");
|
||||
const fs = require("fs");
|
||||
@ -54,12 +54,12 @@ const args = process.argv.slice(2);
|
||||
let additionalKeyword = null;
|
||||
|
||||
for (const arg of args) {
|
||||
if (arg.startsWith('--headless=')) {
|
||||
const val = arg.split('=')[1].toLowerCase();
|
||||
HEADLESS = val === 'true';
|
||||
if (arg.startsWith("--headless=")) {
|
||||
const val = arg.split("=")[1].toLowerCase();
|
||||
HEADLESS = val === "true";
|
||||
}
|
||||
if (arg.startsWith('--keyword=')) {
|
||||
additionalKeyword = arg.split('=')[1];
|
||||
if (arg.startsWith("--keyword=")) {
|
||||
additionalKeyword = arg.split("=")[1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,6 @@ function containsAnyKeyword(text, keywords) {
|
||||
const keywords = [];
|
||||
const csvPath = path.join(process.cwd(), "keywords.csv");
|
||||
|
||||
|
||||
fs.createReadStream(csvPath)
|
||||
.pipe(csv())
|
||||
.on("data", (row) => {
|
||||
@ -117,16 +116,29 @@ fs.createReadStream(csvPath)
|
||||
console.log(`Added additional keyword from CLI: ${additionalKeyword}`);
|
||||
}
|
||||
|
||||
const browser = await chromium.launch({ headless: HEADLESS });
|
||||
const browser = await chromium.launch({
|
||||
headless: HEADLESS,
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
});
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
const page = await Promise.race([
|
||||
context.newPage(),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error("newPage timeout")), 10000)
|
||||
),
|
||||
]).catch((err) => {
|
||||
console.error("Failed to create new page:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto("https://www.linkedin.com/login");
|
||||
await page.fill('input[name="session_key"]', LINKEDIN_USERNAME);
|
||||
await page.fill('input[name="session_password"]', LINKEDIN_PASSWORD);
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForSelector("img.global-nav__me-photo", { timeout: 10000 });
|
||||
await page.waitForSelector("img.global-nav__me-photo", {
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
const seenPosts = new Set();
|
||||
const seenProfiles = new Set();
|
||||
@ -137,7 +149,9 @@ fs.createReadStream(csvPath)
|
||||
await page.goto(searchUrl, { waitUntil: "load" });
|
||||
|
||||
try {
|
||||
await page.waitForSelector(".feed-shared-update-v2", { timeout: 3000 });
|
||||
await page.waitForSelector(".feed-shared-update-v2", {
|
||||
timeout: 3000,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(
|
||||
`---\nNo posts found for keyword: ${keyword}\nDate posted: ${DATE_POSTED}\nSort by: ${SORT_BY}`
|
||||
@ -199,10 +213,9 @@ fs.createReadStream(csvPath)
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const timestamp = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(
|
||||
2,
|
||||
"0"
|
||||
)}-${String(now.getDate()).padStart(2, "0")}-${String(
|
||||
const timestamp = `${now.getFullYear()}-${String(
|
||||
now.getMonth() + 1
|
||||
).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}-${String(
|
||||
now.getHours()
|
||||
).padStart(2, "0")}-${String(now.getMinutes()).padStart(2, "0")}`;
|
||||
const resultsDir = "results";
|
||||
|
||||
19
test.js
Normal file
19
test.js
Normal file
@ -0,0 +1,19 @@
|
||||
console.log("START!");
|
||||
|
||||
const { chromium } = require("playwright");
|
||||
(async () => {
|
||||
console.log("browser!");
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
});
|
||||
console.log("new page!");
|
||||
|
||||
const page = await browser.newPage();
|
||||
console.log("GOTO!");
|
||||
|
||||
await page.goto("https://example.com");
|
||||
console.log("Success!");
|
||||
await browser.close();
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user