Skip to content

Instantly share code, notes, and snippets.

@nachouve
Created April 7, 2015 07:24
Show Gist options
  • Save nachouve/989b45a874a8a70fb881 to your computer and use it in GitHub Desktop.
Save nachouve/989b45a874a8a70fb881 to your computer and use it in GitHub Desktop.
WebScrapper to find a text in a URL response
# Usage:
# python webscrapper_find_text.py
#
# A useful way to execute this script could be:
#
# while true ; do
# python webscrapper_find_text.py ;
# sleep 30;
# done
URL="http://myurl.com"
TEXT_TO_FIND="text_to_find"
import urllib2
from datetime import datetime
def main():
f = urllib2.urlopen(URL)
log_data = f.read()
index = log_data.find(WORD_TO_FIND)
dt = datetime.now().strftime("%Y%m%d-%H%M%S")
if (index > -1 ):
print "[%s] SUCCESS: Found '%s'" % (dt, log_data[index:(index+len(WORD_TO_FIND))])
else:
print "[%s] ERROR: Not found" % dt
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment