,'--lang=en-US,en;q=0.9'],slowMo: 10,userDataDir: './twitter/myUserDataDir'})
const page = await browser.newPage()
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/73.0.3683.75 Safari/537.36');
await page.setExtraHTTPHeaders({
'Accept-Language': 'en-US,en;q=0.9'
});
const context = browser.defaultBrowserContext();
context.overridePermissions("https://twitter.com", ["geolocation", "notifications"]);
await page.setViewport({width: 1280, height: 800});
Run Code Online (Sandbox Code Playgroud)
当 puppeteer 中的 headless = true 时,twitter 网站无法工作,有人可以告诉我如何让它工作吗?
我有一个 (gif) 图像的链接,通过“在新选项卡中打开”手动获取。我希望 Puppeteer 打开图像,然后将其保存到文件中。如果在普通浏览器中执行此操作,我会单击右键并从上下文菜单中选择“保存”。在 Puppeteer 中是否有一种简单的方法来执行此操作?
我们已将 Chromium 配置为在 AWS beanstalk 上打开 PDF。直到最近它都工作得很好。这是出现的新错误:
{“statusCode”:400,“message”:“无法启动浏览器进程!\n/var/app/current/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome:加载时出错共享库:libatk-1.0.so.0:无法打开共享对象文件:没有这样的文件或目录\n\n\n故障排除:https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md \n","错误":"错误的请求"}
不知道是否与Beanstalk Linux配置有关。
为了让 chrome pupeteer 能够正常工作,我们使用了以下配置:
.ebextensions/chrome_pupeteer.config:
packages:
yum:
compat-libtiff3: []
commands:
chrome:
command: curl -k https://intoli.com/install-google-chrome.sh | bash
Run Code Online (Sandbox Code Playgroud)
在 .npmrc 中:
unsafe-perm=true
你能帮我找到另一个解决方案吗?
谢谢
我尝试使用 yum 命令安装软件包:libatk-1.0.so.0
它不起作用:
2023-06-08 11:16:16,116 P7952 [INFO] 命令安装 2023-06-08 11:16:18,226 P7952 [INFO] -------------------- ---命令输出------------------------ 2023-06-08 11:16:18,226 P7952 [INFO] 已加载插件:extras_suggestions、langpacks、优先级, update-motd 2023-06-08 11:16:18,226 P7952 [信息] 没有可用的软件包 libatk1.0-0。2023-06-08 11:16:18,226 P7952 [INFO] 错误:无事可做 2023-06-08 11:16:18,226 P7952 [INFO] ----------------- ------------------------------------------- 2023-06-08 11: 16:18,227 P7952 [错误] 退出,错误代码为 …
使用 render.com 时遇到以下错误:
==\> Running 'node index.js'
Oct 8 07:57:38 PM /opt/render/project/src/node_modules/puppeteer-core/lib/cjs/puppeteer/util/disposable.js:19
Oct 8 07:57:38 PM Symbol.dispose ??= Symbol('dispose');
Oct 8 07:57:38 PM ^^^
Oct 8 07:57:38 PM
Oct 8 07:57:38 PM SyntaxError: Unexpected token '??='
Oct 8 07:57:38 PM at wrapSafe (internal/modules/cjs/loader.js:984:16)
Oct 8 07:57:38 PM at Module.\_compile (internal/modules/cjs/loader.js:1032:27)
Oct 8 07:57:38 PM at Object.Module.\_extensions..js (internal/modules/cjs/loader.js:1097:10)
Oct 8 07:57:38 PM at Module.load (internal/modules/cjs/loader.js:933:32)
Oct 8 07:57:38 PM at Function.Module.\_load (internal/modules/cjs/loader.js:774:14)
Oct 8 07:57:38 PM at Module.require (internal/modules/cjs/loader.js:957:19)
Oct 8 …Run Code Online (Sandbox Code Playgroud) 有一个网页包含许多不断更新的数据行。
行的数目是固定的,因此旧的行会循环输出,并且不会存储在任何地方。
该页面由“加载更多”按钮分解,该按钮将显示直到所有存储的行都显示在页面上。
我需要在Puppeteer / Node.js中编写一个脚本,单击该按钮,直到该按钮不再存在于页面上为止。
然后
...阅读页面上的所有文字。(我已经完成了脚本的这一部分。)
我是Puppeteer的新手,不确定如何设置它。任何帮助将不胜感激。
编辑:
我添加了这个块:
const cssSelector = await page.evaluate(() => document.cssSelector('.u-field-button Button-button-18U-i'));
// Click the "load more" button repeatedly until it no longer appears
const isElementVisible = async (page, cssSelector) => {
await page.waitForSelector(cssSelector, { visible: true, timeout: 2000 })
.catch(() => {
return false;
});
return true;
};
let loadMoreVisible = await isElementVisible(page, cssSelector);
while (loadMoreVisible) {
await page.click(cssSelector);
loadMoreVisible = await isElementVisible(page, cssSelector);
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
Error: Evaluation failed: TypeError: document.cssSelector is …Run Code Online (Sandbox Code Playgroud) 假设我想从搜索“hi google”中抓取结果(只是一个例子)。我正在使用带有 Node.js 的 Puppeteer 进行抓取。我使用以下代码:
const puppeteer = require('puppeteer');
scrape = async function () {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto("https://www.google.com/search?q=hi+google&rlz=1C1CHBF_enUS879US879&oq=hi+google&aqs=chrome..69i57j0l3j46j69i60l3.1667j0j7&sourceid=chrome&ie=UTF-8", { waitUntil: "networkidle2" });
await page.setViewport({ width: 1366, height: 663 });
await page.waitForSelector('.xpd');
let data = await page.evaluate(() => {
return document.querySelectorAll('.xpd')[16];
});
await browser.close();
return data;
}
scrape()
.then(function(result) {
console.log(result);
})
Run Code Online (Sandbox Code Playgroud)
当浏览器启动时,它会立即转到 reCAPTCHA 页面:
有没有办法超越这个问题?我在网上做了一些研究,但这些结果要么是 1. 非常理论化,我不知道如何在我的代码中实现这些,要么 2. Python 解决方案,我不确定其中一些解决方案会如何傀儡师。我遇到的最有用的结果是随机定时抓取以使请求看起来像人类,但正如您所看到的,即使只检索一个数据元素也不起作用,它只会立即将您带到 reCAPTCHA 页面。
谢谢。
我正在尝试在 Firebase 功能上制作一个应用程序(Puppeteer 应用程序),并且我在文件中有以下内容.json。它在本地运行良好。
"custom": {
"following_training": false,
"worked": false
}
Run Code Online (Sandbox Code Playgroud)
但是,当我远程推送它并尝试设置我的代码firebase functions:config:set app="$(cat .env-production.json)"(本质上避免输入长.json配置环境变量字符串)时,我确实收到以下警告:
HTTP Error: 400, Invalid value at 'variable.text' (TYPE_STRING), false
所以是的,它基本上告诉我只发送这种json:
"custom": {
"following_training": "false",
"worked": "false"
}
Run Code Online (Sandbox Code Playgroud)
然后,如果我添加那个to-bool 包来实际检查代码内部,它就会远程工作,如果toBool(local_vars.app.custom.worked) == false......
没有更干净的方法吗...?在 firebase config-env 文档中,实际上没有关于布尔字段的示例。
我在输入时确实得到了预期的内容firebase functions:config:get,但也很奇怪的是,我在 Google Cloud Platform 功能的仪表板中没有任何变量(我得到刷新的代码、Puppeteer 的选项设置等......)。
不确定是否有任何关系。
环境变量可能仅由 Firebase 使用,不需要发送到 GCP。
编辑:工作得很好,不是Firebase问题。
A. 一致性无处不在;运行 !headless,我看它有时工作,有时不工作(比如输入错误的数据),它真的是 50/50。如何优化我的代码以获得 100% 的可靠性?
更新:
通过实现承诺延迟功能和延迟操作来修复不一致。
如何单击既不是提交类型也没有名称和 ID 的按钮?
<button class="sb-frap" data-e2e="sendGift">Send gift</button>
Run Code Online (Sandbox Code Playgroud)
JS路径:
document.querySelector("#js-content > div > div:nth-child(6) > span > div > div.absolute.bg-white.overflow-auto.content___2_l5Q > div > div > div > div > div.invisible.base___3dWsJ.alwaysRelative___3FHV5 > div > span > div > button")
Run Code Online (Sandbox Code Playgroud)
await Promise.all([
await page.waitForSelector(".sb-frap"),
await page.click('button[class=".sb-frap"]'),
]);
})();
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
我想获取一个具有特定类名的字符串,比如说“CL1”。
这是用来做的并且它起作用了:(我们在一个 asycn 函数中)
var counter = await page.evaluate(() => {
return document.querySelector('.CL1').innerText;
});
Run Code Online (Sandbox Code Playgroud)
现在,几个月后,当我尝试运行代码时,出现此错误:
Error: Evaluation failed: TypeError: Cannot read property 'innerText' of null
Run Code Online (Sandbox Code Playgroud)
我console.log()在上一段代码前后做了一些调试,发现这是罪魁祸首。
我查看了网页的代码,里面有特定的类。
但是我发现了另外两个同名的类。
它们三个都嵌套在许多类的深处。
那么,鉴于我知道我感兴趣的那个的类层次结构,选择我想要的那个的正确方法是什么?
编辑:由于有三个同名的类名,我想从第一个中提取信息,我可以在 querySelector() 上使用数组表示法来访问第一个中的信息吗?
EDIT2:我运行这个:
return document.querySelector('.CL1').length;
Run Code Online (Sandbox Code Playgroud)
我得到了
Error: Evaluation failed: TypeError: Cannot read property 'length' of null
Run Code Online (Sandbox Code Playgroud)
这更令人困惑......
编辑 3:我尝试了 Md Abu Taher 的建议,我看到他提供的代码片段没有返回 undefined。这意味着选择器对我的代码可见。
然后我运行这段代码:
var counter = await page.evaluate(() => {
return document.querySelector('#react-root > section > main > div > header > section > ul > …Run Code Online (Sandbox Code Playgroud) puppeteer ×9
node.js ×6
javascript ×5
web-scraping ×3
async-await ×1
chromium ×1
firebase ×1
html ×1
linux ×1
recaptcha ×1
render ×1