-
Notifications
You must be signed in to change notification settings - Fork 8
Update errorChecker.py #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
324de14
Update errorChecker.py
ryma2fhir 22d88ed
Update errorChecker.py
ryma2fhir 9f6b4f0
Update errorChecker.py
ryma2fhir d636b2e
Update errorChecker.py
ryma2fhir 50d56fa
Update linkScraper.py
ryma2fhir 0a296d7
Update errorChecker.py
ryma2fhir 16bc7bb
Update errorChecker.py
ryma2fhir 759a1ed
Update errorChecker.py
ryma2fhir fb7fa00
Update errorChecker.py
ryma2fhir 90aa1a2
Update errorChecker.py
ryma2fhir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,56 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| This script checks webpages for any error messages | ||
| This script checks webpages for any error messages and console logs (not including stack trace) | ||
| """ | ||
|
|
||
| from linkScraper import * | ||
| import re | ||
|
|
||
| def classErrors(warnings, soup): | ||
| '''returns all class errors within the webpage''' | ||
| class_errors = soup.find_all('div',{'class':"error"}) | ||
| if class_errors: | ||
| for err in class_errors: | ||
| warnings.append(err) | ||
| return warnings | ||
|
|
||
| ''' Interates over ListOfLinks returning any pages that have errors ''' | ||
| def FindErrors(url): | ||
| websites = ListOfLinks(url) | ||
| for e in websites: | ||
| url_check = 'https://simplifier.net'+ e | ||
| data_check = requests.get(url_check).text | ||
| soup_check = BeautifulSoup(data_check,"html.parser") | ||
| error = soup_check.find_all('div',{'class':"error"}) | ||
| if error: | ||
| print(url_check) | ||
| for err in error: | ||
| print(err) | ||
| print("\n") | ||
| script_tags = soup_check.find_all('script') | ||
| ''' finds all console.log items, then finds the text associated with it. expect 'console.log(<eror type>,<error var>)' & '<error var> = JSON.stringify(`<text>`). Retuns <error var><text> ''' | ||
| for script in script_tags: | ||
| script_text = script.get_text() | ||
| log_messages = re.findall(r'console\.log\((.*?)\)', script_text) | ||
| for msg in log_messages: | ||
| msg = (msg.replace("'", "").replace(' ', '').split(',')) | ||
| def consoleLog(warnings,soup): | ||
| ''' finds all console.log items, then finds the text associated with it. expect 'console.log(<eror type>,<error var>)' & '<error var> = JSON.stringify(`<text>`). Retuns wanings as <error var><text> ''' | ||
| script_tags = soup.find_all('script') | ||
| for script in script_tags: | ||
| script_text = script.get_text() | ||
| log_messages = re.findall(r'console\.log\((.*?)\)', script_text) | ||
| for msg in log_messages: | ||
| msg = (msg.replace("'", "").replace(' ', '').split(',')) | ||
| lines = script_text.splitlines() | ||
| for line in lines: | ||
| try: | ||
| lines = script_text.splitlines() | ||
| for line in lines: | ||
| if msg[1] in line and 'var' not in line and 'console.log' not in line: | ||
| print(msg[0],line.split("`")[1].rsplit("`", 0)[0]) | ||
| if 'Stacktrace' not in msg[1] and 'var' not in line and 'console.log' not in line: | ||
| warnings.append(msg[0]+" "+msg[1].replace(' At','\nAt')) #+" "+line.split("`")[1].rsplit("`", 0)[0] | ||
| except IndexError: | ||
| pass | ||
| print("Check Complete") | ||
|
|
||
| return(warnings) | ||
|
|
||
| FindErrors(data) | ||
| def printWarnings(warnings, url): | ||
| '''prints all warnings''' | ||
| print(url) | ||
| for x in warnings: | ||
| print(x,"\n") | ||
|
|
||
| ''' Interates over ListOfLinks returning any pages that have errors ''' | ||
| def getSoup(url): | ||
| data = requests.get(url).text | ||
| soup = BeautifulSoup(data,"html.parser") | ||
| return soup | ||
|
|
||
|
|
||
| websites = ListOfLinks(url) | ||
| for suffix in websites: | ||
| warnings = [] | ||
| soup = getSoup('https://simplifier.net'+ suffix) | ||
| warnings = classErrors(warnings, soup) | ||
| warnings = consoleLog(warnings,soup) | ||
| if warnings: | ||
| printWarnings(warnings, 'https://simplifier.net'+ suffix) | ||
|
|
||
| print("Check Complete") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.