Can't log in through Facebook using Puppeteer - Error: Cookies required

百般思念 提交于 2020-04-17 20:15:36

问题


This is my code to login using facebook to a website I'm automating:

const loginButton = await page.waitForXPath(
    "//button[contains(@name, 'login')]"
  );
  const email = await page.waitForSelector("#email");
  const pass = await page.waitForSelector("#pass");

  await page.evaluate((text) => {
    email.value = text;
  }, "my email");

  await page.evaluate((text) => {
    pass.value = text;
  }, "my password");
  await loginButton.click();

Usually it works well, but once every 4 or 5 times, I get the following error after clicking the loginButton:

"Cookies required. Cookies are not enabled on your browser. Please enable cookies in your browser preferences to continue."

I changed from Chromium to Chrome to see if this would solve the issue, but it didn't work.

I also checked the cookies settings and they are enabled.


回答1:


The problem was that the inputs were being filled to quickly and facebook was suspecting that I wasn't a real person. I solved it by introducing some delay between the login steps:

const loginButton = await page.waitForXPath(
    "//button[contains(@name, 'login')]"
  );
  const email = await page.waitForSelector("#email");
  const pass = await page.waitForSelector("#pass");
  await page.waitFor(1000);
  await page.evaluate((text) => {
    email.value = text;
  }, "casas.farach@yahoo.com");
  await page.waitFor(1000);
  await page.evaluate((text) => {
    pass.value = text;
  }, "789654123");
  await page.waitFor(1000);
  await loginButton.click();


来源:https://stackoverflow.com/questions/61251632/cant-log-in-through-facebook-using-puppeteer-error-cookies-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!