-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathURL.py
More file actions
27 lines (23 loc) · 693 Bytes
/
URL.py
File metadata and controls
27 lines (23 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import urllib2
import time
class URL:
def __init__(self, url):
self.url = url
def fetch(self):
print 'Attempting url fetch.'
OK = False
tries = 0
while not OK:
try:
response = urllib2.urlopen(self.url)
print 'Success : ' + self.url
OK = True
except urllib2.HTTPError as e:
tries = tries + 1
if tries >= 256:
return -1
print 'Failure.\nAn HTTP error occured : ' + str(e.code)
print 'Refetching : ' + self.url
time.sleep(4)
html = response.read()
return html