Skip to content

Instantly share code, notes, and snippets.

@DerekHawkins
Last active April 24, 2020 06:00
Show Gist options
  • Save DerekHawkins/b913ec0df500e8872ba89ea6ca309865 to your computer and use it in GitHub Desktop.
Save DerekHawkins/b913ec0df500e8872ba89ea6ca309865 to your computer and use it in GitHub Desktop.
service_url = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed/"
def speed_test_url(url, device):
params = {
"?url": url,
'strategy': device,
'key': key,
}
data = urllib.parse.urlencode(params, doseq=True)
main_call = urllib.parse.urljoin(service_url, data)
main_call = main_call.replace(r'%3F', r'?')
return main_call
test_url = speed_test_url(url='https://example.com', device='mobile')
response = requests.get(test_url).json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment