-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_downloader.py
46 lines (38 loc) · 1.27 KB
/
html_downloader.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# encoding: utf-8
__author__ = 'yueyt'
from urllib.parse import urljoin
import requests
import config
class HtmlDownloader(object):
def __init__(self):
self.headers = config.request_header
self.s = requests.session()
self.s.headers = config.request_header
self.s.post(config.login_url, data=config.login_post_data)
# post downloader
def post_downloader(self, type, req_data):
processor = config.processor.get(type)
if not processor:
print("i can't get processor", __name__, type, req_data)
return
url = urljoin(config.root_url, processor.get('url'))
payload = processor.get('payload')
# dict
if req_data:
payload.update(req_data)
r = self.s.post(url, data=payload)
# debug
if type == 'loaninfo_detail_downloader':
print('>>>', payload)
return r.content
# get downloader
def get_downloader(self, type, url):
processor = config.processor.get(type)
if not processor:
print("i can't get processor", __name__, type, url)
return
url = urljoin(config.root_url, url)
print('U' * 10, url)
r = self.s.get(url)
return r.content