问题
So I am trying to have my code do something if the URL contains this: https://kith.com/throttle/queue?
After the '?' there can be anything, so I only want it to identify 'https://kith.com/throttle/queue?'
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 (If the URL doesn't contain that): do nothing and go to the next line of code
回答1:
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.
}
来源:https://stackoverflow.com/questions/62725357/if-url-contains-function-in-puppeteer