Created
November 6, 2024 11:13
-
-
Save kinngh/380c090e07f09fdad4a67dc0d782653e to your computer and use it in GitHub Desktop.
Pull passwordless demo store URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getHrefFromUrl(url) { | |
try { | |
const response = await fetch(url, { | |
headers: { | |
"User-Agent": | |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", | |
Accept: | |
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | |
"Accept-Language": "en-US,en;q=0.5", | |
Connection: "keep-alive", | |
}, | |
}); | |
const html = await response.text(); | |
const pattern = /<a[^>]*href="([^"]*)"[^>]*>\s*View demo store\s*<\/a>/; | |
const match = html.match(pattern); | |
const href = match ? match[1] : null; | |
console.log(href); | |
return href; | |
} catch (error) { | |
console.error("Error:", error); | |
} | |
} | |
// Usage | |
const url = "https://apps.shopify.com/{app-handle}"; | |
await getHrefFromUrl(url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why?
Usecase