Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (75 sloc) 3.19 KB
# coding: utf-8
import json
import requests
from bs4 import BeautifulSoup
import helper
from checks.google_pagespeed import google_pagespeed_check
def mobileFriendlyCheck(request_url, api_key):
""" Example of Python talking to Google Search Console URL Testing Tools API.
attributes: 'request_url' for the URL to test, 'api_key' for the API key credentials
fetched at Googles API Console
payload = {'url': request_url, 'key': api_key}
r =
# print(r.text)
# print(r.url)
json_data = json.loads(r.text.replace('\'', '"'))
# print(str(json_data['mobileFriendliness']))
return json_data['mobileFriendliness']
print('Error! Failed to request API for {0}'.format(request_url))
def httpStatusCodeCheck(url, simulate_404=False, time_out=30.000):
"""Checking HTTP status code, or a presumed 404 message
Attributes: string url, bool simulate_404, decimal time_out
if (simulate_404):
url = '{0}/{1}'.format(url,
'sp4m-b34t2-k3b4b?') # changing the URL, trying to provoke a 404 Not Found
# consider sitemap.xml, robots.txt, humans.txt, etc
r = requests.get(url, timeout=time_out)
return r.status_code
except: # not sure which error code to choose, but 520-522 seems reasonable according to
return '520'
def checkForFiles(url, file="robots.txt"):
""" Used to check a domain for interesting default files
Attributes: string url, string file
# interesting files are robots.txt, humans.txt, sitemap.xml
return_dict = {}
url = '{0}/{1}'.format(url, file)
return_dict[url] = httpStatusCodeCheck(url)
return return_dict
def thirdPartiesCheck(url):
"""Checking third parties used on the URL
Attributes: string url
get_content = helper.httpRequestGetContent(url)
get_content = BeautifulSoup(get_content, "html.parser")
for findings in'img[src*="//"]'):
for findings in'iframe[src*="//"]'):
for findings in'link[href*="//"]'):
for findings in'script[src*="//"]'):
for findings in'script[src*="//"]'):
# komplettera med the usual suspects? Som '//' i fritext?
# inbäddade kartor, videoklipp, teckensnitt?
If file is executed for itself
if __name__ == '__main__':
# print(httpStatusCodeCheck(''))
# print(mobileFriendlyCheck('', privatekeys.googleMobileFriendlyApiKey))
result = google_pagespeed_check('')
# thirdPartiesCheck('')
for key, value in result.items():
print("{key}: {value}".format(key=key, value=value))