if URL contains function in puppeteer

≯℡__Kan透↙ 提交于 2020-08-09 07:02:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!