Skip to content

Instantly share code, notes, and snippets.

@sivel
Created May 11, 2010 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/397500 to your computer and use it in GitHub Desktop.
Save sivel/397500 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import urllib, re, sys
def content_match(url, match, nocase):
uh = urllib.urlopen(url)
if re.search(match, uh.read(), re.I if nocase else 0) and uh.getcode() == 200:
return [True, uh.geturl(), uh.getcode()]
else:
return [False, uh.geturl(), uh.getcode()]
def usage():
print 'Usage: ', sys.argv[0], '[http://url-to-test.com] [match-content] [optional-flags]'
print 'Optional Flags:'
print '\t-i\t\tCase Insensitive Regex'
def main():
if len(sys.argv) < 3:
usage()
return
try:
if sys.argv[3] and sys.argv[3] == '-i':
nocase = True
else:
nocase = False
except IndexError:
nocase = False
match = content_match(sys.argv[1], sys.argv[2], nocase)
if not match[0]:
print match[2], 'Failure Detected.'
else:
print match[2], 'Success Detected.'
if sys.argv[1] != match[1]:
print 'Redirect Detected:', sys.argv[1], '->', match[1]
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment