【发布时间】:2023-02-03 04:09:30
【问题描述】:
所以我正在创建一个基本上使用您的帐户登录耐克的软件,它将导航到您最近的订单,抓取该信息,并将其发送回不和谐的网络钩子。耐克似乎同时使用了 Akamai 和 Kasdada,我设法找到了通过 Akamai 的解决方法,但不幸的是无法通过 Kasada。我收到错误“解析服务器错误”,这是 Kasada 检测到您使用某种形式的自动化并阻止了您。我已经尝试了一些方法,例如无头浏览器、使用代理、禁用自动闪烁功能,但这一切似乎都是徒劳的。在网络抓取方面,我充其量只是个初学者,所以请放轻松。我正在使用 NodeJS 和 Puppeteer 来创建这个程序。下面是我当前的代码以及它在哪里中断。 “忽略我的 cmets”
const prompt = require("prompt-sync")({ sigint: true });
const fs = require("fs");
const { Webhook, MessageBuilder } = require("discord-webhook-node");
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
/* const proxy = '208.194.232.77:8080';
const username = '3cw7073bgg';
const password = '2c0309ffc2'; */
( async () => {
// Established Initial Browser
const browser = await puppeteer.launch({
headless: false, // false = Shows Browser | true = Browser Not Shown
executablePath: `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`,
userDataDir: `/Users/Library/Application Support/Google/Chrome/Default`,
ignoreDefaultArgs: ['--enable-automation'],
args: [
// `--proxy-server=${proxy}`, //
`--disable-blink-features=AutomationControlled`,
`--enable-blink-feautres=IdleDetection`
]
});
// Required Inputs The User Needs To Enter
/*let webhookURL = prompt("What is your discord webhook? ");*/
let accountEmail = prompt("What is your email address? ");
let accountPassword = prompt("What is your account password? ");
// Opens New Tab
const page = await browser.newPage(); // Opens up a new tab within the browser
// Stores Cookies To Local Storage To Reuse
/* const saveCookie = async (page) => {
const cookies = await page.cookies();
const cookieJson = JSON.stringify(cookies, null, 2);
await fs.writeFile('cookies.json', cookieJson)
}
// Loads The Cookies Stored
const loadCookie = async (page) => {
const cookieJson = await fs.readFile('cookies.json');
const cookies = JSON.parse(cookieJson);
await page.setCookie(...cookies);
} */
// Browser Variables & Properties
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36');
await page.setJavaScriptEnabled(true); // This can be set true or false or completely removed. Haven't really noticed anything
await page.setCacheEnabled(true);
await page.setBypassCSP(true);
await page.setViewport({ width: 1920, height: 1080 }); // Browser Size
// await page.authenticate({ username, password }); // This calls from the proxy data above to use to login into proxy
await page.setDefaultNavigationTimeout(60000);
await page.goto("https://www.nike.com/"); // This is where you input the site that you want the script to open
console.log('Browser has successfully opened!');
// ---------------- Login Process ---------------- //
// Navigates To The Login Page
await page.waitForSelector('.nav-btn.p0-sm.d-sm-b.body-4.u-bold.ml2-sm.mr2-sm');
await page.click('.nav-btn.p0-sm.d-sm-b.body-4.u-bold.ml2-sm.mr2-sm');
console.log("Navigating To Login Page...")
// Inputs Account Email
await page.waitForSelector('#username');
await page.click("#username", { delay: 500 });
console.log("Typing Email Address...");
await page.keyboard.type(`${accountEmail}`, { delay: 750 });
console.log('Account Email Entered!');
await page.waitForSelector('.css-14l6ovh.btn-primary-dark.btn-lg')
await page.keyboard.press("Enter", { delay: 30000 });``` <= It breaks here after waiting for server response.
【问题讨论】:
标签: javascript node.js puppeteer