python - 抓取到页面中的pdf地址后,如何下载到本地?
阿神
阿神 2017-04-17 17:21:47
0
3
374

想从一个网站上批量下载文章,现在可以得到文章的名字。
但是打开pdf网页后,连接中的空格被替换成了 %20这样的字符。
字符替换我自己可以处理,但是有了链接后怎么下载呢?
也就是说怎么执行浏览器里save link as这个动作?
我如何向服务器发送这种请求并下载这些文章?

阿神
阿神

闭关修行中......

reply all(3)
PHPzhong

urlretrieve(url, filename=None, reporthook=None, data=None)
Try this function to download the url locally.

伊谢尔伦

%20 means spaces.
Can you just process it again?

刘奇

I checked online and found that solving this problem is quite simple.
You can refer to here

Direct

url = 'FILE ADDR'
r = requests.get(url)
with open('1.pdf', 'wb') as f:
    f.write(r.content)
    
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template