refactor config proxy
This commit is contained in:
parent
e0d2058fa0
commit
064d8a8349
@ -63,6 +63,17 @@ else:
|
|||||||
except:
|
except:
|
||||||
print('[-]Config.ini read failed! Please use the offical file!')
|
print('[-]Config.ini read failed! Please use the offical file!')
|
||||||
|
|
||||||
|
def get_network_settings():
|
||||||
|
try:
|
||||||
|
proxy = config["proxy"]["proxy"]
|
||||||
|
timeout = int(config["proxy"]["timeout"])
|
||||||
|
retry_count = int(config["proxy"]["retry"])
|
||||||
|
assert timeout > 0
|
||||||
|
assert retry_count > 0
|
||||||
|
except:
|
||||||
|
raise ValueError("[-]Proxy config error! Please check the config.")
|
||||||
|
return proxy, timeout, retry_count
|
||||||
|
|
||||||
def getDataState(json_data): # 元数据获取失败检测
|
def getDataState(json_data): # 元数据获取失败检测
|
||||||
if json_data['title'] == '' or json_data['title'] == 'None' or json_data['title'] == 'null':
|
if json_data['title'] == '' or json_data['title'] == 'None' or json_data['title'] == 'null':
|
||||||
return 0
|
return 0
|
||||||
@ -87,16 +98,11 @@ def getXpathSingle(htmlcode,xpath):
|
|||||||
return result1
|
return result1
|
||||||
|
|
||||||
def get_html(url,cookies = None):#网页请求核心
|
def get_html(url,cookies = None):#网页请求核心
|
||||||
try:
|
proxy, timeout, retry_count = get_network_settings()
|
||||||
proxy = config['proxy']['proxy']
|
|
||||||
timeout = int(config['proxy']['timeout'])
|
|
||||||
retry_count = int(config['proxy']['retry'])
|
|
||||||
except:
|
|
||||||
print('[-]Proxy config error! Please check the config.')
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < retry_count:
|
while i < retry_count:
|
||||||
try:
|
try:
|
||||||
if not str(config['proxy']['proxy']) == '':
|
if not proxy == '':
|
||||||
proxies = {"http": "http://" + proxy,"https": "https://" + proxy}
|
proxies = {"http": "http://" + proxy,"https": "https://" + proxy}
|
||||||
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36'}
|
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36'}
|
||||||
getweb = requests.get(str(url), headers=headers, timeout=timeout,proxies=proxies, cookies=cookies)
|
getweb = requests.get(str(url), headers=headers, timeout=timeout,proxies=proxies, cookies=cookies)
|
||||||
|
@ -5,8 +5,11 @@ success_output_folder=JAV_output
|
|||||||
soft_link=0
|
soft_link=0
|
||||||
|
|
||||||
[proxy]
|
[proxy]
|
||||||
|
# modify this line to your proxy server, leave black proxy= for direct connection
|
||||||
proxy=127.0.0.1:1081
|
proxy=127.0.0.1:1081
|
||||||
|
# timeout must always be greater than zero
|
||||||
timeout=10
|
timeout=10
|
||||||
|
# retry must always be greater than zero
|
||||||
retry=3
|
retry=3
|
||||||
|
|
||||||
[Name_Rule]
|
[Name_Rule]
|
||||||
|
10
core.py
10
core.py
@ -212,15 +212,7 @@ def creatFolder(success_folder, location_rule, json_data, Config): # 创建文
|
|||||||
|
|
||||||
# =====================资源下载部分===========================
|
# =====================资源下载部分===========================
|
||||||
def DownloadFileWithFilename(url, filename, path, Config, filepath, failed_folder): # path = examle:photo , video.in the Project Folder!
|
def DownloadFileWithFilename(url, filename, path, Config, filepath, failed_folder): # path = examle:photo , video.in the Project Folder!
|
||||||
retry_count = 0
|
proxy, timeout, retry_count = get_network_settings()
|
||||||
proxy = ''
|
|
||||||
timeout = 0
|
|
||||||
try:
|
|
||||||
proxy = Config['proxy']['proxy']
|
|
||||||
timeout = int(Config['proxy']['timeout'])
|
|
||||||
retry_count = int(Config['proxy']['retry'])
|
|
||||||
except:
|
|
||||||
print('[-]Proxy config error! Please check the config.')
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
while i < retry_count:
|
while i < retry_count:
|
||||||
|
10
core2.py
10
core2.py
@ -207,15 +207,7 @@ def creatFolder(success_folder, location_rule, json_data, Config): # 创建文
|
|||||||
|
|
||||||
# =====================资源下载部分===========================
|
# =====================资源下载部分===========================
|
||||||
def DownloadFileWithFilename(url, filename, path, Config, filepath, failed_folder): # path = examle:photo , video.in the Project Folder!
|
def DownloadFileWithFilename(url, filename, path, Config, filepath, failed_folder): # path = examle:photo , video.in the Project Folder!
|
||||||
retry_count = 0
|
proxy, timeout, retry_count = get_network_settings()
|
||||||
proxy = ''
|
|
||||||
timeout = 0
|
|
||||||
try:
|
|
||||||
proxy = Config['proxy']['proxy']
|
|
||||||
timeout = int(Config['proxy']['timeout'])
|
|
||||||
retry_count = int(Config['proxy']['retry'])
|
|
||||||
except:
|
|
||||||
print('[-]Proxy config error! Please check the config.')
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
while i < retry_count:
|
while i < retry_count:
|
||||||
|
Loading…
Reference in New Issue
Block a user