Skip to content

Instantly share code, notes, and snippets.

@khambadkone
Last active May 28, 2016 07:25
Show Gist options
  • Save khambadkone/7e28c9edc51ae50511751da97e656492 to your computer and use it in GitHub Desktop.
Save khambadkone/7e28c9edc51ae50511751da97e656492 to your computer and use it in GitHub Desktop.
Check if a site contains a word
# Google does a great job searching for keywords on a site
# If there are none, their reponse always includes "did not match any documents"
import urllib2
import sys
site = sys.argv[1]
word = sys.argv[2]
# need the user-agent so google wont return a 403
headers = {'User-agent':'Mozilla/11.0'}
req = urllib2.Request('https://www.google.co.in/search?q='+site+'+site:'+word,None,headers)
site = urllib2.urlopen(req)
data = site.read()
if "did not match any documents" in data:
print "Not there"
else:
print "There"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment