def __init__(self, url): parsed_url = urlparse(url) self.domain = parsed_url.netloc self.scheme = parsed_url.scheme self.path = parsed_url.path self.request = request_page(self.generate_url()) self.status_code = self.request.status_code self.headers = self.request.headers self.soup = BeautifulSoup(self.request.content, 'html.parser')
def is_https(self): https_save = self.audit_results["common_seo_issues"]["audits"]["https"] if request_page("https://" + self.domain).status_code == 200: self.https = True https_save["score"] = True else: self.https = False https_save["score"] = False self.audit_results["common_seo_issues"]["audits"]["https"] = https_save
def robots_finder(self): request = request_page(self.generate_url() + "/robots.txt") if request.status_code == 200: self.robots = True robot_answer = self.audit_results["common_seo_issues"]["audits"][ "robots"] robot_answer["score"] = True robot_answer["result"] = self.generate_url() + "/robots.txt" robot_answer["success"] = robot_answer["success"].replace( "{value}", self.generate_url() + "/robots.txt") self.audit_results["common_seo_issues"]["audits"][ "robots"] = robot_answer self.find_sitemap(request.text)
def audit_google_lighthouse_seo(url): pagespeed = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=" result = request_page(pagespeed + url + "&category=seo", timeout=30) content = result.json() result_seo = {} result_seo["summary"] = {} result_seo["summary"]["requestedUrl"] = content["lighthouseResult"][ "requestedUrl"] result_seo["summary"]["finalUrl"] = content["lighthouseResult"]["finalUrl"] result_seo["summary"]["timing"] = content["lighthouseResult"]["timing"][ "total"] result_seo["summary"]["date"] = content["lighthouseResult"]["fetchTime"] result_seo["results"] = {} for key in content["lighthouseResult"]["audits"]: result_seo["results"][key] = {} result_seo["results"][key]["short_desc"] = content["lighthouseResult"][ "audits"][key]["title"] result_seo["results"][key]["long_desc"] = content["lighthouseResult"][ "audits"][key]["description"] result_seo["results"][key]["score"] = content["lighthouseResult"][ "audits"][key]["score"] return result_seo
def is_https(self): if request_page("https://" + self.domain).status_code == 200: self.https = True else: self.https = False
def populate_request(self): self.request = request_page(self.generate_url()) self.status_code = self.request.status_code
def audit_google_lighthouse_full(url): pagespeed = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=" + url + "&category=BEST_PRACTICES&category=ACCESSIBILITY&category=PERFORMANCE&category=PWA&category=SEO" if current_app.config['GOOGLE_API_KEY'] != "None": pagespeed += "&key=" + current_app.config["GOOGLE_API_KEY"] result = request_page(pagespeed, timeout=30) return result.json()