Created
September 27, 2011 16:57
-
-
Save netdesign/1245606 to your computer and use it in GitHub Desktop.
roboparser example
This file contains hidden or 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
| 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 "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