使用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