node.js - 如何使用剧作家登录谷歌帐户?
问题描述
我有以下源代码并以 headful 模式运行它。我可以输入电子邮件地址。但是,在那之后,有消息说“无法登录。为了保护您,您无法从此设备登录。请稍后再试,或从其他设备登录。”。
我需要设置额外的标题或其他东西吗?
这是我的源代码。
const playwright = require('playwright');
const cookiePath = '/home/ubuntu/.config/chromium/Default';
browser['chromium'] = await playwright['chromium'].launchPersistentContext(cookiePath,{
headless: false,
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
});
const page = await browser['chromium'].newPage();
const login_url = "https://accounts.google.com/signin/v2/identifier?hl=ja&flowName=GlifWebSignIn&flowEntry=ServiceLogin";
await page.goto(login_url);
await page.fill('#identifierId',userinfo['id']);
await page.click("#identifierNext");
await page.fill('[name=password]',userinfo['password']);
await page.click("#passwordNext");
解决方案
我的解决方案:
const { chromium } = require("playwright");
(async () => {
const browser = await chromium.launch({
headless: false,
args: ["--disable-dev-shm-usage"],
});
const context = await browser.newContext({});
const page = await context.newPage();
const navigationPromise = page.waitForNavigation({
waitUntil: "domcontentloaded",
});
await page.setDefaultNavigationTimeout(0);
await page.goto(
"https://accounts.google.com/signin/v2/identifier?hl=en&flowName=GlifWebSignIn&flowEntry=ServiceLogin"
);
await navigationPromise;
await page.waitForSelector('input[type="email"]');
await page.type('input[type="email"]', "youremail");
await page.click("#identifierNext");
await page.waitForSelector('input[type="password"]', { visible: true });
await page.type('input[type="password"]', "yourpassword");
await page.waitForSelector("#passwordNext", { visible: true });
await page.click("#passwordNext");
await navigationPromise;
//you are in
我认为您也可以使用 Puppeteer 搜索登录到 google。
推荐阅读
- reactjs - 在 webpack 构建期间未将 Favicon 添加到构建文件夹
- vba - 选择文件夹(收件箱)并在移动的电子邮件中执行宏
- r - 删除 RStudio 并重新安装后,无法访问站点
- node.js - MongoParseError: URI 没有主机名、域名和 tld
- sql-server - 列出未连接到的实例下的数据库
- python-3.x - 如何使用 IPOPT 在 Pyomo 中指定渐变
- python - 哈希方法在 python 2 中默认,而不是 python 3
- python - PySpark Foreach
- vb.net - 打开远程桌面并连接到计算机
- curl - 使用 J 从安全链接中读取 CSV 文件