我正在尝试使用 Puppeteer 解析页面。但是,页面上的脚本之一正在尝试覆盖createElement
文档对象的属性,这会导致错误。错误信息是:
Uncaught TypeError: Cannot assign to read only property 'createElement' of object '#<HTMLDocument>'
经过研究,我意识到document
Puppeteer 中的属性是由代理对象保护的。
当我document.createElement
在 Puppeteer 控制台中运行时,我得到以下信息:
Proxy\xc2\xa0{length: 1, name: "createElement"}
但是,当我在 Chrome 中执行相同操作时,它是一个常规函数,而不是代理。
\n有没有办法让 Puppeteer 以与 Chrome 相同的方式运行并使document
对象可写?
编辑:
\n我已经尝试过这个,但没有成功。document.createElement
仍然是一个代理。
await page.evaluateOnNewDocument(() => {\n document.createElement = document.__proto__.createElement;\n})\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
612 次 |
最近记录: |