我想使用 Puppeteer 来响应页面更新。该页面显示项目,当我离开页面打开时,新项目可能会随着时间的推移出现。例如,每 10 秒添加一个新项目。
我可以使用以下内容来等待页面初始加载时的项目:
await page.waitFor(".item");
console.log("the initial items have been loaded")
Run Code Online (Sandbox Code Playgroud)
我怎样才能等待/捕捉未来的物品?我想实现这样的东西(伪代码):
await page.goto('http://mysite');
await page.waitFor(".item");
// check items (=these initial items)
// event when receiving new items:
// check item(s) (= the additional [or all] items)
Run Code Online (Sandbox Code Playgroud) 我有一个代码如下:
page.click('div.button-table div:contains(Who) div.square-button:nth-child(1)')
Run Code Online (Sandbox Code Playgroud)
当 puppeteer 运行此代码时,它会引发错误:
简短的
Failed to execute 'querySelector' on 'Document': 'div.button-table div:contains(Who) div.square-button:nth-child(1)' is not a valid selector.
满的
Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': 'div.button-table div:contains(Who) div.square-button:nth-child(1)' is not a valid selector.
at __puppeteer_evaluation_script__:1:33
at ExecutionContext.evaluateHandle (node_modules/puppeteer/lib/ExecutionContext.js:124:13)
at <anonymous>
-- ASYNC --
at ExecutionContext.<anonymous> (node_modules/puppeteer/lib/helper.js:144:27)
at ElementHandle.$ (node_modules/puppeteer/lib/ExecutionContext.js:529:50)
at ElementHandle.<anonymous> (node_modules/puppeteer/lib/helper.js:145:23)
at Frame.$ (node_modules/puppeteer/lib/FrameManager.js:456:34)
at <anonymous>
-- ASYNC --
at Frame.<anonymous> (node_modules/puppeteer/lib/helper.js:144:27)
at Frame.click (node_modules/puppeteer/lib/FrameManager.js:735:31)
at Frame.<anonymous> (node_modules/puppeteer/lib/helper.js:145:23)
at Page.click (node_modules/puppeteer/lib/Page.js:973:29) …Run Code Online (Sandbox Code Playgroud) 大约一个月前,我写了一个问题,询问是否可以将 Brave Browser 与 puppeteer 一起使用;答案是肯定的,我对其进行了测试,一切正常;今天我尝试运行相同的代码,但出现错误ERROR: process "xxxxx" not found
关于这个问题的任何想法?
const puppeteer = require('puppeteer');
(async()=>{
const browser = await puppeteer.launch({
executablePath:"C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
headless:false,
devtools:false,
})
const page = await browser.newPage()
})()
Run Code Online (Sandbox Code Playgroud) 我面临的问题是 Puppeteer 不加载使用相对路径指定的资源(例如background.png在 imagesrc或 css中url())。这样,我使用setContent()结果加载本地文件的内容与我执行相同操作但使用goto(file://).
显然,然后使用“setContent()”,页面停留在“about:page”,并阻止加载具有相对路径的资源。我想知道是否有任何方法可以指定文档位置并从字符串加载内容?
我会使用goto,但我需要先用 Handlebar 预处理 html。
现在,我执行以下操作:
await page.goto(framePath);
let content = await page.content();
//Preprocess content here
await page.setContent(processedContent);
Run Code Online (Sandbox Code Playgroud)
但感觉不太对劲,我想知道是否有更好的解决方案。
我找不到任何从 python playwright 返回外部 html 的方法 page.locator(selector, **kwargs)。我错过了什么吗?
locator.inner_html(**kwargs)确实存在。但是,我尝试使用 pandas.read_html ,但它在表定位器内部 html 上失败,因为它触发了表标记。
我目前正在做的是使用 bs4 来解析 page.content()。就像是:
soup = BeautifulSoup(page.content(), 'lxml')
df = pd.read_html(str(soup.select('table.selector')))
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Web应用程序创建一个nuget程序包,但它不产生任何.nupkg输出。我正在使用Visual Studio 2017 15.3.0。
要创建项目,请执行以下操作:
然后,转到包含csproj文件的目录中的命令提示符,然后键入:“ Dotnet Pack”
我只得到以下输出:
.NET Core的Microsoft(R)Build Engine版本15.3.409.57025版权所有(C)Microsoft Corporation。版权所有。
但是没有创建nuget包。我期望的是这样的:
为App生产Nuget包“ App.1.0.0”
我是否还需要对csproj文件做其他事情?
在 C# 中,我会这样写:
string input;
do
{
Console.Write("Enter an equation: ");
input = Console.ReadLine();
} while (FSharpOption<Expression>.get_IsNone(Infix.TryParse(input)));
Run Code Online (Sandbox Code Playgroud)
这将提示用户重复输入一个方程,直到他们输入一个可以解析的方程。我将如何在 F# 中执行此操作?
我的 html 文档是
<div class="inner-column">
<div data-thing="abc1"></div>
<div data-thing="abc2"></div>
<div data-thing="abc3"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
如何在 .inner-column 类的 div 中获取所有“数据事物”值(例如 [“abc1”、“abc2”、“abc3”])?
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.setViewport({width: 1440, height: 1200})
await page.goto('https://www.example.com')
const data = await page.content();
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud) 我正在单击包含确认对话框但无法关闭的链接。
我尝试按“Enter”并使用 puppeteer 的方法关闭并接受对话框,但什么也没发生。
链接:
<a onclick="return confirm('Yes?');" id="link" href="google.com">
Run Code Online (Sandbox Code Playgroud)
我试过:
page.on('dialog', async dialog => {
console.log('here'); //does not pass
await dialog.accept();
//await dialog.dismiss();
});
Run Code Online (Sandbox Code Playgroud)
和
await page.keyboard.press('Enter');
await page.keyboard.press(String.fromCharCode(13));
Run Code Online (Sandbox Code Playgroud) 我正在尝试访问谷歌在剧作家中注册的新弹出窗口,但无法做到这一点。
await page.waitForSelector(signUpWithGoogle, { state: 'visible' })
await page.focus(signUpWithGoogle)
await page.click(signUpWithGoogle)
await page.fill('//input[@type="email"]', email)
Run Code Online (Sandbox Code Playgroud) javascript ×7
node.js ×6
puppeteer ×6
.net ×2
playwright ×2
.net-core ×1
asp.net ×1
brave ×1
dotnet-cli ×1
e2e-testing ×1
f# ×1
jestjs ×1
python ×1