简体   繁体   English

在手册页上启动 Puppeteer

[英]Launch Puppeteer on a manual Page

Is it possible to manually navigate to a Page, then launch a Puppeteer Script there, navigate to a different Page, launch script there, and so on..是否可以手动导航到页面,然后在那里启动 Puppeteer 脚本,导航到不同的页面,在那里启动脚本,等等..

I already did a bit of research but couldn't find anything.我已经做了一些研究,但找不到任何东西。

I need to autofill a Calendar but its a little bit difficult to automate the whole Process, so it would be nice if I could navigate manually and launch the script when needed我需要自动填充日历,但是自动化整个过程有点困难,所以如果我可以手动导航并在需要时启动脚本会很好

Does anyone know if this is possible??有谁知道这是否可能?

You could code an interactive console app, Like the one explained here .你可以编写一个交互式控制台应用程序,就像这里解释的那样。 On that app, you would launch a browser with headless in false, navigate where you want to go, and then from the console app you could type a command like fillform and execute the puppeteer code you want to run.在该应用程序上,您将启动一个带有 false 无头的浏览器,导航到您想去的地方,然后在控制台应用程序中,您可以键入像fillform这样的命令并执行您想要运行的fillform代码。

Not sure why someone down voted?不知道为什么有人投了反对票?

Yeah it's possible.是的,这是可能的。 It's not recommended.不推荐。 It's better to work your way through the errors and then understand how page automation really works.最好先解决错误,然后了解页面自动化的真正工作原理。 This is the point of Puppeteer.这就是 Puppeteer 的重点。 It's also already possible to run JavaScript on a page in chrome, using the console in dev-tools.也可以使用开发工具中的控制台在 chrome 页面上运行 JavaScript。

But if you wanted to manually navigate to a page using puppeteer, then run 'macros' on the page using node.js based on a condition, you'd want to do something like this:但是,如果您想使用 puppeteer 手动导航到页面,然后根据条件使用 node.js 在页面上运行“宏”,您需要执行以下操作:

  1. headless: false launch (obviously so you can see the browser) headless:错误启动(显然是为了你可以看到浏览器)

  2. have your script/fill in function wait for an event on the page like a request which indicates the page was refreshed.让您的脚本/填充函数等待页面上的事件,例如指示页面已刷新的请求。 You might be able to use page.on() event to trigger the code wait for the request to finish.您可以使用 page.on() 事件触发代码等待请求完成。

     await page.setRequestInterception(true); page.on('request', request => { // Override headers const headers = Object.assign({}, request.headers(), { foo: 'bar', // set "foo" header origin: undefined, // remove "origin" header }); request.continue({headers}); });

from puppeteer 来自傀儡师

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM