使用Python去搞web获取数据相关的东西的确方便。302重定向也能自动解决。
如下FIddler抓包:
这个还是挺好的,可以直接处理302,挂证书也方便:
获取数据源码如下:
- def getContent(self, path):
- if os.path.exists(path):
- with open(path, "r", encoding="utf-8") as f:
- return f.read()
-
- return ''
下载文件源码如下:
- def downLoadFile(self, url, fileName):
- # r = requests.get(url)
- #r = requests.get(url, vertify = False)
-
- print("开始下载" + fileName)
- r = requests.get(url, proxies = {"http": "http://127.0.0.1:8888", "https": "http:127.0.0.1:8888"},
- verify=r"D:/Fiddler/FiddlerRoot.pem")
- print(fileName + "下载结束")
- if r.status_code == 200:
- #200直接下载
- with open(fileName, "wb") as code:
- code.write(r.content)
- pass
- pass