Python3 怎样将下载链接转成文字 50
就是链接上没有拓展名如,jpg.rar之类的,如http://www.zei8.net/plus/download.php?open=2&id=71758&uhash=9...
就是链接上没有拓展名如 ,jpg .rar之类的 ,如http://www.zei8.net/plus/download.php?open=2&id=71758&uhash=9ba7075e685a0e4a4ab71803 怎样将他变为文件,就具体代码或者方法
urllib.urlretrieve() 已经使用过 展开
urllib.urlretrieve() 已经使用过 展开
2个回答
展开全部
我只能说这是一个Python3.4以上版本的bug,至今还没有在版本中解决。
具体情况可以查下issue17214
Title: http.client.HTTPConnection.putrequest encode error
Type:behavior
Stage:patch review
Components:Library (Lib)Versions:Python 3.6, Python 3.5, Python 3.4
不过幸运的是已经给出了Patch,可以自行修改,修改方法如下:
diff --git a/Lib/http/client.py b/Lib/http/client.py
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -263,6 +263,7 @@
headers.append(line)
if line in (b'\r\n', b'\n', b''):
break
+ print(headers)
hstring = b''.join(headers).decode('iso-8859-1')
return email.parser.Parser(_class=_class).parsestr(hstring)
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -652,11 +652,13 @@
"%s - Redirection to url '%s' is not allowed" % (msg, newurl),
headers, fp)
- if not urlparts.path:
- urlparts = list(urlparts)
- urlparts[2] = "/"
- newurl = urlunparse(urlparts)
-
+ urlpartslist = list(urlparts)
+ path = urlparts.path if urlpaths.path else "/"
+ # parse_headers() decodes from iso-8859-1 and unquotes, undo damage
+ path = urlparts.path.encode("iso-8859-1")
+ urlpartslist[2] = quote(path)
+
+ newurl = urlunparse(urlpartslist)
newurl = urljoin(req.full_url, newurl)
# XXX Probably want to forget about the state of the current
博思aippt
2024-07-20 广告
2024-07-20 广告
**AI一键生成PPT免费版**为满足广大用户的需求,我们博思云创科技特推出AI一键生成PPT免费版。用户只需简单输入需求,AI技术便能智能分析并快速生成高质量PPT。此版本功能强大且易于操作,无需专业设计技能,即可轻松打造出令人满意的演示...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询