Skip to content

Commit

Permalink
Added request timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris committed Jul 8, 2013
1 parent b515473 commit 8f98237
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions webarticle2text.py
Expand Up @@ -24,7 +24,7 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""
VERSION = (1, 2, 5)
VERSION = (1, 2, 6)
__version__ = '.'.join(map(str, VERSION))
import os
import sys
Expand Down Expand Up @@ -296,7 +296,8 @@ def extractFromURL(url,
verbose=False,
encoding=None,
filters=None,
userAgent=None):
userAgent=None,
timeout=5):
"""
Extracts text from a URL.
Expand Down Expand Up @@ -339,7 +340,7 @@ def extractFromURL(url,
if userAgent:
headers['User-agent'] = str(userAgent)
request = urllib2.Request(url=url, headers=headers)
response = urllib2.urlopen(request)
response = urllib2.urlopen(request, timeout=timeout)
html = response.read()

# If no encoding guess given, then attempt to determine encoding automatically.
Expand Down

0 comments on commit 8f98237

Please sign in to comment.