好友
阅读权限20
听众
最后登录1970-1-1
|
刹那光华
发表于 2021-10-22 02:15
QQ浏览器直接打开链接显示:
无法安全地连接到此页面这可能是因为该站点使用过期的或不安全的 TLS 安全设置。如果这种情况持续发生,请与网站的所有者联系。
火狐浏览器没问题
云服务器的IE浏览器也能正常打开
PHP可以正常下载
file_put_contents("小说/".$_GET[ 'name' ].".txt", file_get_contents("https://xiazai.xqishu.com/txt/".$_GET[ 'name' ].".txt"));
唯独Python下不了,报错信息:
'Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)
[Python] 纯文本查看 复制代码
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/%E5%BC%82%E4%B8%96%E4%B9%8B%E4%BB%99%E4%B8%B4%E8%AF%B8%E7%95%8C.txt[/url]
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) |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|