From 5fc2d3684abca8860956a5d1577da7e8c9a41fd8 Mon Sep 17 00:00:00 2001 From: alphapapa Date: Sun, 3 Apr 2016 21:32:36 -0500 Subject: [PATCH] Use Mozilla User-Agent Use a "Mozilla" user-agent to avoid HTTP 403 errors. Fixes #71. --- readability/readability.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/readability/readability.py b/readability/readability.py index 2aaac62..de19a7c 100755 --- a/readability/readability.py +++ b/readability/readability.py @@ -600,12 +600,15 @@ def main(): file = None if options.url: + headers = {'User-Agent': 'Mozilla/5.0'} if sys.version_info[0] == 3: import urllib.request, urllib.parse, urllib.error - file = urllib.request.urlopen(options.url) + request = urllib.request.Request(options.url, None, headers) + file = urllib.request.urlopen(request) else: import urllib2 - file = urllib2.urlopen(options.url) + request = urllib2.request(options.url, None, headers) + file = urllib2.urlopen(request) else: file = open(args[0], 'rt') try: