Skip to content

Commit

Permalink
Merge branch 'hunkim-http_keep_alive'
Browse files Browse the repository at this point in the history
  • Loading branch information
e9t committed Dec 3, 2015
2 parents bbaee5e + 9408dda commit c2fa63f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bills/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
'Referer': 'http://likms.assembly.go.kr/bill/jsp/BillSearchResult.jsp',
}

s = requests.Session()

def check_dir(directory):
if not os.path.exists(directory):
os.makedirs(directory)
Expand All @@ -25,7 +27,7 @@ def get_elem_texts(page, x):

def get_webpage(url, outp):
try:
r = requests.get(url, headers=HEADERS, stream=True)
r = s.get(url, headers=HEADERS, stream=True)
assert r.ok
except (requests.exceptions.RequestException, AssertionError) as e:
import sys
Expand All @@ -39,7 +41,7 @@ def get_webpage(url, outp):
f.write(block)

def get_webpage_text(url):
r = requests.get(url, headers=HEADERS)
r = s.get(url, headers=HEADERS)
return r.content

def read_json(fname):
Expand All @@ -57,4 +59,4 @@ def read_webpage(filename):
def write_json(data, fn):
with open(fn, 'w') as f:
json.dump(data, f, indent=2)
print 'Data written to ' + fn
#print 'Data written to ' + fn

0 comments on commit c2fa63f

Please sign in to comment.