Cha*_*mer 3 python wget github
我正在创建一个从 GitHub 存储库获取文件的程序,但raw.githubusercontent.com不适用于二进制文件。如果 .ico 文件不是二进制文件,请告诉我如何下载它们。
我正在使用wget.download(),像这样:
import wget\nurl = \xe2\x80\x9c https://raw.githubusercontent.com/user/repository/branch/file\xe2\x80\x9d\nwget.download(url)\nRun Code Online (Sandbox Code Playgroud)\n有什么建议么?
\n如果添加?raw=true到文件末尾,它应该可以工作。
例如:我的主页的.ico无法在浏览器中查看。
# Original Link
https://github.com/hayesall/hayesall.github.io/blob/master/favicon.ico
# (1) Appended with `?raw=true`
https://github.com/hayesall/hayesall.github.io/blob/master/favicon.ico?raw=true
# (2) Going through githubusercontent
https://raw.githubusercontent.com/hayesall/hayesall.github.io/master/favicon.ico
Run Code Online (Sandbox Code Playgroud)
选项 (1) 或 (2) 可以通过以下方式下载wget:
# Original Link
https://github.com/hayesall/hayesall.github.io/blob/master/favicon.ico
# (1) Appended with `?raw=true`
https://github.com/hayesall/hayesall.github.io/blob/master/favicon.ico?raw=true
# (2) Going through githubusercontent
https://raw.githubusercontent.com/hayesall/hayesall.github.io/master/favicon.ico
Run Code Online (Sandbox Code Playgroud)
检查下载的文件:
$ file favicon.ico
favicon.ico: MS Windows icon resource - 1 icon, 16x16, 32 bits/pixel
Run Code Online (Sandbox Code Playgroud)
在原子中:
版本信息:
$ wget --version
GNU Wget 1.19.4 built on linux-gnu.
$ pip freeze | grep "wget"
wget==3.2
Run Code Online (Sandbox Code Playgroud)
如果这仍然不起作用,可能是有问题wget(最近一次更新是在 2015 年)。这是使用以下替代解决方案requests:
import wget
url = "https://github.com/hayesall/hayesall.github.io/blob/master/favicon.ico?raw=true"
wget.download(url)
100% [.......................] 1150 / 1150
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2905 次 |
| 最近记录: |