我找不到对用户进行身份验证的方法。 当您手动启动 Node JS 服务器时,这工作正常(是的,它的代码很丑陋(:
if (data.URL.includes("https://share.url.com")) {
await page.type('#userNameInput', 'user');
await page.type('#passwordInput', 'pass');
await page.click('#submitButton');
await page.waitForNavigation({waitUntil: 'load'});
await page.waitFor(6000);
}
SharePoint 不知道我的用户数据,因此他们将我导航到登录页面,我可以在其中填写登录信息,然后移动到我请求的网站。但与此同时,进行了 2 项更改:1.此登录页面不再存在,如果找不到登录信息,我只会链接到一个页面,其中显示"抱歉您无权访问此页面"。第二个问题或更改是节点服务器由服务启动。
最后,我只需要以某种方式访问该页面,然后截取它的屏幕截图。但是身份验证让我很麻烦。我现在需要解决此问题的方法,但我无法考虑其他解决方案。
木偶师身份验证:
await page.authenticate({
username: "user",
password: "pass"
});
这不起作用,或者将其与身份验证标头一起使用也不起作用。
在浏览器中保存用户信誉(铬(铬((:
我试图保存浏览器内页面的用户信誉,但这没有任何影响。
网址身份验证:
我试图像 (https://user:pass@share.url.com/bla/site.aspx( 一样在 URL 内进行身份验证,但它不起作用。
我不知道如何处理这个问题,你有没有任何建议,我可以用其他方式尝试这个,或者你在我的代码或想法中看到错误?
感谢比尔盖茨
关于
在浏览器中保存用户信誉(铬(铬((:
我也有类似的情况 - 我想在登录时从 facebook 截图。为了实现它,我做了一些步骤,例如:
1( 创建临时用户数据目录
mkdir /tmp/puppeteer_test
2(使用这些参数运行Chrome
/usr/bin/google-chrome --user-data-dir=/tmp/puppeteer_test --password-store=basic
3(转到 facebook.com,登录然后关闭浏览器
4(使用适当的参数运行木偶师:
const browser = await puppeteer.launch({
headless: false,
executablePath: '/usr/bin/google-chrome',
args: ['--user-data-dir=/tmp/puppeteer_test']
});
const page = await browser.newPage();
await page.goto('https://facebook.com', { waitUntil: 'networkidle2' });
await page.screenshot({path: 'facebook.png'});
await browser.close();
我正在为SharePoint做以下操作
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({width: 1920, height: 1080});
// Open SharePoint page
console.log("Opening page");
await page.goto('https://mytenant.sharepoint.com/sites/mysite');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Page opened");
// Input username
console.log("Inputting username");
await page.type('#i0116', 'user@mytenant.com');
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Username input completed");
// Input password
console.log("Inputting password");
await page.type('#i0118', 'password123');
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Password input completed");
// Stay signed in
console.log("staying signed in");
await page.keyboard.press('Enter');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("staying signed in completed");
// Wait, because rendering is picky
await page.waitFor(6000);