Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import urllib.request
  2. import os
  3. import time
  4.  
  5. class AppURLopener(urllib.request.FancyURLopener):
  6. version = "Mozilla/5.0"
  7.  
  8. opener = AppURLopener()
  9.  
  10. def downloadSite(url):
  11. response = opener.open(url)
  12. return response.read()
  13. def searchKey(text, keyword, plug, timeout, default):
  14.  
  15. #Store keys found
  16. keysFound = []
  17.  
  18. #Slide through every character
  19. for i in range(0, len(text)):
  20.  
  21. #keyword lenth and resulting snippet of text searched
  22. keywordLength = len(keyword)
  23. currentSearch = text[i:i + keywordLength]
  24.  
  25. if(currentSearch == keyword):
  26.  
  27. #start of id to be extracted
  28. start = i + keywordLength
  29.  
  30. #track which search
  31. j = start
  32.  
  33. #plug lenth
  34. plugLenth = len(plug)
  35. searchResult = default
  36.  
  37. #search until plug found of length exceded
  38. while True:
  39.  
  40. plugSearch = text[j:j + plugLenth]
  41.  
  42. if(plugSearch == plug):
  43. searchResult = text[start:j]
  44. break
  45.  
  46. if(j > start + timeout):
  47. print("Plug Not Found")
  48. break
  49.  
  50. j += 1
  51.  
  52. #add newly found key to results
  53. keysFound.append(searchResult)
  54.  
  55. return keysFound
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement