Created
April 7, 2015 07:24
-
-
Save nachouve/989b45a874a8a70fb881 to your computer and use it in GitHub Desktop.
WebScrapper to find a text in a URL response
This file contains 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
# 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