You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
robotparser doesn't return crawl delay for default entry #69586
After changeset http://hg.python.org/lookup/dbed7cacfb7e, calling the crawl_delay method for a robots.txt files that has a crawl-delay for * useragents always returns None.
Ex:
Python 3.6.0a0 (default:1aae9b6a6929+, Oct 9 2015, 22:08:05)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.robotparser
>>> parser = urllib.robotparser.RobotFileParser()
>>> parser.set_url('https://www.carthage.edu/robots.txt')
>>> parser.read()
>>> parser.crawl_delay('test_robotparser')
>>> parser.crawl_delay('*')
>>> print(parser.default_entry.delay)
120
>>>
This fix breaks the unit tests though. I am not sure how to go about checking those as this would be my first contribution to python and an open source project in general.
pwirtz commented on Oct 14, 2015
pwirtzmannequin
MannequinAuthor
More actions
On further inspection of the tests, it appears that the way in which the tests are written, a test case can only be tested for one useragent at a time. I will attempt to work on the tests so work correctly. Any advice would be much appreciated.
Thanks for the patch Peter(and welcome to Python and open source development). I have a WIP patch to rewrite test_robotparser in a less magic way. So we can ignore test failures for now. I'll take a closer look to your patch.
pwirtz commented on Oct 14, 2015
pwirtzmannequin
MannequinAuthor
More actions
Ok, for the mean time, I reworked the test so it appears to test correctly and tests passes. There does seem to be some magic, so I do hope I did not overlook anything. Here is the new patch.
Activity
pwirtz commentedon Oct 14, 2015
After changeset http://hg.python.org/lookup/dbed7cacfb7e, calling the crawl_delay method for a robots.txt files that has a crawl-delay for * useragents always returns None.
Ex:
Excerpt from https://www.carthage.edu/robots.txt:
User-agent: *
Crawl-Delay: 120
Disallow: /cgi-bin
I have written a patch that solves this. With patch, output is:
This also applies to the request_rate method.
pwirtz commentedon Oct 14, 2015
This fix breaks the unit tests though. I am not sure how to go about checking those as this would be my first contribution to python and an open source project in general.
pwirtz commentedon Oct 14, 2015
On further inspection of the tests, it appears that the way in which the tests are written, a test case can only be tested for one useragent at a time. I will attempt to work on the tests so work correctly. Any advice would be much appreciated.
berkerpeksag commentedon Oct 14, 2015
Thanks for the patch Peter(and welcome to Python and open source development). I have a WIP patch to rewrite test_robotparser in a less magic way. So we can ignore test failures for now. I'll take a closer look to your patch.
pwirtz commentedon Oct 14, 2015
Ok, for the mean time, I reworked the test so it appears to test correctly and tests passes. There does seem to be some magic, so I do hope I did not overlook anything. Here is the new patch.
berkerpeksag commentedon Sep 11, 2016
I've now updated Lib/test/test_robotparser.py (bpo-25497) Peter, do you have time to update your patch? Thanks!
berkerpeksag commentedon Sep 18, 2016
Here's an updated patch.
python-dev commentedon Sep 18, 2016
New changeset d5d910cfd288 by Berker Peksag in branch '3.6':
Issue bpo-25400: RobotFileParser now correctly returns default values for crawl_delay and request_rate
https://hg.python.org/cpython/rev/d5d910cfd288
New changeset 911070065e38 by Berker Peksag in branch 'default':
Issue bpo-25400: Merge from 3.6
https://hg.python.org/cpython/rev/911070065e38