Skip to content

Fix spider #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Safer fetching
  • Loading branch information
jayvdb committed Jul 28, 2016
commit 5ee2066b49de79c06c9b3bbf1ae4deaa3e2d6a67
20 changes: 18 additions & 2 deletions utils/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,25 @@ def check_robots(self, urls):
robotURL = urllib_parse.urlunsplit(robotURL)
self.robotParser.set_url(https://github.com/robotURL)
try:
self.robotParser.read()
resp, content = self.http.request(robotURL, "GET")
except Exception as e:
print('Failed to read {0}: {1}'.format(robotURL, e), file=sys.stderr)
print("Failed to fetch {0}: {1}".format(robotURL, e), file=sys.stderr)
urls.remove(url)
continue

if resp['status'] == '404':
# no robots.txt to check
continue

if resp['status'] not in ('200', '304'):
print("Fetch {0} status {1}".format(url, resp['status']), file=sys.stderr)
urls.remove(url)
continue

try:
self.robotParser.parse(content.decode('utf8'))
except Exception as e:
print('Failed to parse {0}: {1}'.format(robotURL, e), file=sys.stderr)
urls.remove(url)
continue

Expand Down