作者martinqqq321 (盖棉被开冷气)
看板Python
标题[问题] 爬虫程式如何判断某些连结的档名
时间Mon Mar 1 21:17:25 2021
我写的程式会先用googlesearch.search去找我想要下载的档案,之後会用
r = request.get(url)
with open(name,’wb’) as f:
F.write(r.content)
的方式把档案存下来
最麻烦的地方主要是name的部分,我目前是直接从网址去判断存下的档名和副档名
但有时候google search会出现以下的结果:
Http://www......./index.php?Action=downloadfile&file=............
问题就在downloadfile&file後面都是无法辨识的乱码,请问要如何去侦测这种网址的档
名和档案类型呢
如果直接从chrome去打开这些网址的话,会直接跳到下载档案的画面
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 223.140.154.176 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1614604647.A.044.html
2F:→ zerof: or just search MDN for “Content-Disposition” 03/02 02:05
3F:推 cloudandfree: Regular expression 03/05 16:33
4F:推 mychiux413: 你的r.headers里有线索 03/17 01:29