您的位置:首頁技術文章
文章詳情頁

requests - 請問Python下載文件問題

瀏覽:113日期:2022-06-30 13:27:59

問題描述

在” http://www.chinadrugtrials.or...”這個網頁上點擊下載按鈕之后會下載一個DOC文件, 希望用Python做到自動下載, 目前是文件可以下載了, 但卻打不開

個人考慮也許不能把get到的內容直接寫入文件或者是重定向的問題, 但Google了之后發現沒有其他方法, 查看文檔也沒有什么收獲

下面是網頁截圖和下載語句, 麻煩各位幫忙看一下是哪里出了問題, 請指教, 謝謝

[網頁如下]如果網頁什么都不顯示的話, 直接點擊右上角的查詢就有信息了, 不用注冊、登陸requests - 請問Python下載文件問題

[代碼如下]

import requestsheader = {’User-Agent’: ’Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36’}url = ’http://www.chinadrugtrials.org.cn/exportdoc/clinicaltrials.searchlistdetail’data = {’ckm_id’: ’eda4593539334baea5f58828360d5dd8’,’ckm_index’: 1,’button2’: ’’}ses = requests.session()get = ses.post(url, headers=header, data=data)with open(’./1.doc’, ’wb’) as file: file.write(get.content)print(’Done!’)

問題解答

回答1:

我用了你的代碼去執行, 是可以打開的 python版本2.7

requests - 請問Python下載文件問題

標簽: Python 編程
相關文章:
国产综合久久一区二区三区