INNER CODE UNIT · TypeScript

getUserPageUrl

mifi/instauto · src/index.ts:406

  const getUserPageUrl = (username: string) => `${instagramBaseUrl}/${encodeURIComponent(username)}`;

  function isAlreadyOnUserPage(username: string) {
    const url = getUserPageUrl(username);
    // optimization: already on URL? (ignore trailing slash)
    return (page.url().replace(/\/$/, '') === url.replace(/\/$/, ''));
  }

  // How to test xpaths in the browser:
  // document.evaluate("your xpath", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue
  async function getXpathElement(xpath: string, opts?: WaitForSelectorOptions): Promise<ElementHandle | null> {
    try {
      return await page.waitForSelector(`::-p-xpath(${xpath})`, opts);
    } catch {
      logger.debug(`Element not found for xpath: ${xpath}`);
      return null;
    }
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…