python - 如何翻译url编码的字符串python
问题描述
此代码应该将pdf列表下载到目录中
for pdf in preTag:
pdfUrl = "https://the-eye.eu/public/Books/Programming/" +
pdf.get("href")
print("Downloading...%s"% pdfUrl)
#downloading pdf from url
page = requests.get(pdfUrl)
page.raise_for_status()
#saving pdf to new directory
pdfFile = open(os.path.join(filePath, os.path.basename(pdfUrl)), "wb")
for chunk in page.iter_content(1000000):
pdfFile.write(chunk)
pdfFile.close()
我过去os.path.basename()
只是为了确保文件会真正下载。但是,我想知道如何将文件名从3D%20Printing%20Blueprints%20%5BeBook%5D.pdf
“3D Printing Blueprints.pdf”更改为
解决方案
您可以使用urllib2 取消引用功能:
import urllib2
print urllib2.unquote("3D%20Printing%20Blueprints%20%5BeBook%5D.pdf") #3D Printing Blueprints.pdf
推荐阅读
- r - 是否可以使用输入变量选择绘图的位置?
- google-sheets - 谷歌助手输入仅限于从 excel 中选择的下拉选项
- python - 采用可变输入张量列表的自定义 Tensorflow 操作
- selenium - 第二个 Selenium 测试不适用于 Jenkins(click() 问题)
- php - 我应该在 img 标签中写什么,这样才有效
- css - 了解如何使用 bootstrap 4 使 div 居中
- wix - 升级到 64 位版本时将应用程序从“Program Files x86”移动到“Program Files”
- file-io - 如何在跳过与特定模式匹配的行时从文件中读取行?
- flutter - 为什么一个功能在它的时间之前工作?
- ruby-on-rails - 分页删除控制器中的 AR 范围