Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Created March 12, 2019 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamletbatista/65247c49050914558c35e1a8e06da443 to your computer and use it in GitHub Desktop.
Save hamletbatista/65247c49050914558c35e1a8e06da443 to your computer and use it in GitHub Desktop.
#convert relative URLs to absolute
from urllib.parse import urljoin
#relative 404 URLs from Search Console API: webmasters.urlcrawlerrorssamples.list
pageUrl = "product/mad-for-plaid-flannel-dress" #missing forward slash
print(urljoin("https://www.example.com/", pageUrl))
#Output -> https://www.example.com/product/mad-for-plaid-flannel-dress
#relative links from Google Analytics API: ga:landingPagePath
landingPagePath = "/about-chc/clinicians/audiology-technology/" #including forward slash
print(urljoin("https://www.example.com/", landingPagePath))
#Output -> https://www.example.com/about-chc/clinicians/audiology-technology/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment