def isUsingManyExternalResources(url: str) -> int: noOfExtRes = 0 MANY = 30 try: source = utils.getLoadedHtmlFromUrl(url) soup = BeautifulSoup(source, 'html.parser') domain = utils.getDomainFromUrl(url) imageSources = compileList(soup, 'img', 'src') scriptSources = compileList(soup, 'script', 'src') styleSources = compileList(soup, 'link', 'href') videoSources = compileList(soup, 'video', 'src') audioSources = compileList(soup, 'audio', 'src') iframeSources = compileList(soup, 'iframe', 'src') embedSources = compileList(soup, 'embded', 'src') objectSources = compileList(soup, 'object', 'data') sourceSources = compileList(soup, 'source', 'src') sources = imageSources + scriptSources + styleSources + videoSources + audioSources + iframeSources + embedSources + objectSources + sourceSources for s in sources: if str(s).startswith('http'): if utils.getDomainFromUrl(str(s)) != domain: noOfExtRes += 1 if noOfExtRes >= MANY: return 1 else: return 0 except: return -1
def isOpenningNewWindow(url: str) -> int: hasNewWindow = False try: source = utils.getLoadedHtmlFromUrl(url) soup = BeautifulSoup(source, 'html.parser') scriptSources = compileList(soup, 'script', 'src') scriptInners = compileList(soup, 'script', 'innerHtml') anchorTargets = compileList(soup, 'a', 'target') for s in scriptSources: try: script = utils.getHttpResponse(s) if re.match('window.open', script): hasNewWindow = True except: pass for i in scriptInners: if re.match('window.open', str(i)): hasNewWindow = True for a in anchorTargets: if a == '_blank': hasNewWindow = True if hasNewWindow: return 1 return 0 except: return -1
def isStringInPage(url: str, searchTarget: str) -> int: """Return 1 if the the searchTarget exists in the page of the given URL""" try: source = utils.getLoadedHtmlFromUrl(url) except: return -1 return 1 if searchTarget in source else 0
def isPageContainingDownload(url: str) -> int: """Return 1 if the page contains 'download' in the page of the given URL""" try: source = utils.getLoadedHtmlFromUrl(url) result1 = 'download' in source result2 = 'Download' in source except: return -1 return 1 if (result1 or result2) else 0
def isPageContainingActionRequired(url: str) -> int: """Return 1 if the page contains 'action required' in the page of the given URL""" try: source = utils.getLoadedHtmlFromUrl(url) result1 = 'action required' in source result2 = 'Action Required' in source result3 = 'ACTION REQUIRED' in source except: return -1 return 1 if (result1 or result2 or result3) else 0
def isPageContainingUrgent(url: str) -> int: """Return 1 if the page contains 'urgent' in the page of the given URL""" try: source = utils.getLoadedHtmlFromUrl(url) result1 = 'urgent' in source result2 = 'Urgent' in source result3 = 'URGENT' in source except: return -1 return 1 if (result1 or result2 or result3) else 0
def isPageContainingCreditCard(url: str) -> int: """Return 1 if the page contains 'credit card' in the page of the given URL""" try: source = utils.getLoadedHtmlFromUrl(url) result1 = 'credit card' in source result2 = 'credit-card' in source result3 = 'Credit Card' in source except: return -1 return 1 if (result1 or result2 or result3) else 0
def isBlockingRightClick(url: str) -> int: isBlocking = False try: source = utils.getLoadedHtmlFromUrl(url) soup = BeautifulSoup(source, 'html.parser') scriptSources = compileList(soup, 'script', 'src') scriptInners = compileList(soup, 'script') # For external scripts for s in scriptSources: try: # Download the script content script = utils.getHttpResponse(s) # For document.addEventListener('contextmenu', event => event.preventDefault()); if re.search('contextmenu', script) and re.search( 'preventDefault', script): isBlocking = True except: pass # For checking <script>CONTENT</script> for s in scriptInners: if re.search('contextmenu', s) and re.search('preventDefault', s): isBlocking = True # For checking body <body oncontextmenu="return false;" try: if soup.body['oncontextmenu'] and re.search( 'return\sfalse', soup.body['oncontextmenu']): isBlocking = True except KeyError: pass if isBlocking: return 1 return 0 except: return -1
def testHelloWorldCodepen(self): self.assertTrue("Hello World" in utils.getLoadedHtmlFromUrl( 'https://cdpn.io/rayyue300/fullpage/RwNLBpa'))