我正在尝试关闭Puppeteer中的对话框。我尝试转换原始的Puppeteer指令,但是没有用。
我正在爬网的网站从body onload
中引发警报。
这是我到目前为止没有运气的东西。
$js_function = JsFunction::createWithAsync()
->body('async dialog => {
await dialog.dismiss();
}');
$this->page->on('dialog', $js_function);
$this->page->goto($this->url);
原始的伪造者文档:https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#class-dialog
您几乎做对了所有事情,但是有一个小错误。
这里是正确的代码:
$js_function = JsFunction::createWithAsync()
->parameters(['dialog'])
->body('await dialog.dismiss()');
$this->page->on('dialog', $js_function);
$this->page->goto($this->url);