Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import os
- import time
- class AppURLopener(urllib.request.FancyURLopener):
- version = "Mozilla/5.0"
- opener = AppURLopener()
- def downloadSite(url):
- response = opener.open(url)
- return response.read()
- def searchKey(text, keyword, plug, timeout, default):
- #Store keys found
- keysFound = []
- #Slide through every character
- for i in range(0, len(text)):
- #keyword lenth and resulting snippet of text searched
- keywordLength = len(keyword)
- currentSearch = text[i:i + keywordLength]
- if(currentSearch == keyword):
- #start of id to be extracted
- start = i + keywordLength
- #track which search
- j = start
- #plug lenth
- plugLenth = len(plug)
- searchResult = default
- #search until plug found of length exceded
- while True:
- plugSearch = text[j:j + plugLenth]
- if(plugSearch == plug):
- searchResult = text[start:j]
- break
- if(j > start + timeout):
- print("Plug Not Found")
- break
- j += 1
- #add newly found key to results
- keysFound.append(searchResult)
- return keysFound
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement