Skip to content

Instantly share code, notes, and snippets.

@netdesign
Created September 27, 2011 16:57
Show Gist options
  • Select an option

  • Save netdesign/1245606 to your computer and use it in GitHub Desktop.

Select an option

Save netdesign/1245606 to your computer and use it in GitHub Desktop.
roboparser example
import robotparser
toget = "http://johannburkard.de/blog/www/spam/The-top-10-spam-bot-user-agents-you-MUST-block-NOW.html"
roboturl = "http://johannburkard.de/robots.txt"
userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"
pars = robotparser.RobotFileParser()
pars.set_url(roboturl)
pars.read()
print "Should be False" #and is False
print pars.can_fetch("*", toget)
print
print "Should be True" #but is False
print pars.can_fetch(userAgent, toget)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment