import
requests
import
time
import
logging
def
output(title
=
'
',info='
'):
try
:
timeInfo
=
time.strftime(
"%Y-%m-%d %H:%M:%S"
, time.localtime())
outputInfo
=
'[%s]\n%s => %s'
%
(timeInfo,title,info)
logging.debug(outputInfo)
print
(outputInfo)
return
outputInfo
except
requests.exceptions.RequestException as e:
logging.debug(title,
'输出错误'
,e)
def
DownLoad(name):
try
:
url
=
'https://xiazai.xqishu.com/txt/%s.txt'
%
name
path
=
'小说/%s.txt'
%
name
Headers
=
{
'Host'
:
'www.xqishu.me'
,
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'
,
'Accept'
:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
,
'Accept-Language'
:
'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2'
,
'Accept-Encoding'
:
'gzip, deflate, br'
,
'Alt-Used'
:
'xiazai.xqishu.com'
,
'Connection'
:
'keep-alive'
,
'Upgrade-Insecure-Requests'
:
'1'
,
'Sec-Fetch-Dest'
:
'document'
,
'Sec-Fetch-Mode'
:
'navigate'
,
'Sec-Fetch-Site'
:
'cross-site'
,
'Sec-Fetch-User'
:
'?1'
,
}
output(
'GET请求'
,
'Url:'
+
url
+
' Path:'
+
path)
r
=
requests.get(url, headers
=
Headers,stream
=
True
)
output(
'GET结果'
,
'StatusCode:'
+
str
(r.status_code))
if
r.status_code
=
=
200
:
with
open
(path,
"wb"
) as code:
code.write(r.content)
return
True
except
requests.exceptions.RequestException as e:
output(
'Error'
,e)
return
False
if
__name__
=
=
'__main__'
:
load
=
DownLoad(
'九极剑神'
)
print
(load)