admin管理员组文章数量:1222271
This is the analyzed page /.
In this page the content of the following days is loaded dynamically with the js without changing the URL of the site (you can try it at the top right of the table).
Using puppeteer, with the following code
await page.goto ('/');
it loads the contents of today's page. Is there a way to load the page with tomorrow's content? i have to scrape information from the matches of the following days
the function in js executable from terminal for change day is:
> set_calendar_date ('1')
This is the analyzed page https://www.diretta.it/.
In this page the content of the following days is loaded dynamically with the js without changing the URL of the site (you can try it at the top right of the table).
Using puppeteer, with the following code
await page.goto ('https://www.diretta.it/');
it loads the contents of today's page. Is there a way to load the page with tomorrow's content? i have to scrape information from the matches of the following days
the function in js executable from terminal for change day is:
> set_calendar_date ('1')
Share
Improve this question
asked Feb 10, 2019 at 22:38
MenneMenne
1271 gold badge1 silver badge5 bronze badges
1
|
1 Answer
Reset to default 15What you are looking for is the page.evaluate()
function.
This function lets you run any JS function in the page context.
In simpler terms, running page.evaluate()
is akin to opening Dev tools and writing set_calendar_date('1')
there directly.
Here is a working snippet, don't hesitate to pass {headless: false}
to puppeteer.launch()
if you want to see it working with your own eyes.
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.diretta.it/');
await page.evaluate(() => {
set_calendar_date ('1');
});
await page.waitFor(500); //Wait a bit for the website to refresh contents
//Updated table is now available
})();
本文标签: javascriptpuppeteer execute a js function on the chosen pageStack Overflow
版权声明:本文标题:javascript - puppeteer execute a js function on the chosen page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739377919a2160573.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
await page.$eval('html', () => set_calendar_date ('1'));
– Krzysztof Krzeszewski Commented Feb 10, 2019 at 22:42