python调用wget下载ftp或https的文件,需要验证用户名和密码,但用户名包含特殊字符时,大家咋处理的?
重点:有个https网站需要登录后才能下载他的文件,并且登录的用户名或密码中包含了@或:字符。用wget如何下载呢?
简单的情况:
比如有个ftp文件我要下载,这个ftp需要登录。
用户名是:testuser
密码是:testpass
文件地址是:ftp://127.0.0.1/file/bin.rar
用wget下载时直接一句搞定: wget ftp://testuser:testpass@127.0.0.1/file/bin.rar
这种组合式的URL中,就直接包含了登录的账号和密码,格式就是ftp://用户名:密码@地址
但这样有一个弊端:
当用户名为test@user
登录密码为test:pass
如果写成wget ftp://test@user:test:pass@127.0.0.1/file/bin.rar
里面的多个@或:特殊符号,会引起歧义了。
看wget的帮助文档,有一段信息:
FTP options:
--ftp-user=USER set ftp user to USER.
--ftp-password=PASS set ftp password to PASS.
--no-remove-listing don't remove `.listing' files.
--no-glob turn off FTP file name globbing.
--no-passive-ftp disable the "passive" transfer mode.
--retr-symlinks when recursing, get linked-to files (not dir).
--preserve-permissions preserve remote file permissions.
所以问题解决了,可以这样来写 wget --ftp-user="test@user" --ftp-password="test:pass" 127.0.0.1/file/bin.rar
但对于需要用户名和密码登录的https的网站,wget就没有提供可以输入用户名和密码的参数了。
比如我在网上找的这个地址:https://tools.cisco.com/CCIE/Schedule_Lab/CCIEOnline/jsp/UpdateProfile_Form.jsp
用wget下载这个文件时,如果用户名和密码不包含特殊字符,可以直接这样:
wget --no-check-certificate https://testuser:testpass@tools.cisco.com/CCIE/Schedule_Lab/CCIEOnline/jsp/UpdateProfile_Form.jsp
这样就能下回这个jsp文件了。
但是如果用户名或密码包含@或:这样的特殊字符,这样拼接就不行了。
有没有哪位知道这种情况如何解决呢?