如果 URL 包含 puppeteer 中的函数 [英] if URL contains function in puppeteer

查看:26
本文介绍了如果 URL 包含 puppeteer 中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,如果 URL 包含以下内容,我会尝试让我的代码执行某些操作:https://kith.com/throttle/queue?

So I am trying to have my code do something if the URL contains this: https://kith.com/throttle/queue?

在?"之后可以有任何东西,所以我只希望它识别https://kith.com/throttle/queue?"

After the '?' there can be anything, so I only want it to identify 'https://kith.com/throttle/queue?'

我正在使用 puppeteer 并希望它像这样工作:如果 URL 包含https://kith.com/throttle/queue?"然后等到它通过队列 (page.waitForNavigation({ waitUntil: 'networkidle2' }) 将等待它通过队列

I am using puppeteer and want it to work like this: If the URL contains 'https://kith.com/throttle/queue?' then wait until it passes the queue (page.waitForNavigation({ waitUntil: 'networkidle2' }) would work for waiting until it's through the queue

Else(如果 URL 不包含):什么都不做,转到下一行代码

Else (If the URL doesn't contain that): do nothing and go to the next line of code

推荐答案

这个网址很难理解,但是如果这是当前页面的网址,你可以试试这个:

It is hard to understand how do you get this URL, but if this is a URL of a current page, you can try this:

const url = await page.evaluate(() => location.href);

if(url.startsWith('https://kith.com/throttle/queue?')) {
  // Wait for navigation.
} else {
  // Do nothing.
}

这篇关于如果 URL 包含 puppeteer 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆