After clicking the download button on the "http://www.chinadrugtrials.or..." page, a DOC file will be downloaded. I hope to use Python to automatically download it. Currently, the file can be downloaded, but it cannot be opened. open
Personally, I thought that the obtained content may not be written directly into the file or it may be a redirection problem, but after searching on Google, I found that there is no other way, and there is nothing gained by looking at the documentation.
The following is a screenshot of the webpage and the download statement. Could you please help me find out what went wrong? Please give me some advice. Thank you
[Webpage is as follows] If nothing is displayed on the webpage, just click the query in the upper right corner to get the information. No need to register or log in
[code show as below]
import requests
header = {'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!')
I used your code to execute, and it can be opened with python version 2.7