requests - Questions about downloading files in Python
大家讲道理
大家讲道理 2017-05-24 11:34:58
0
1
596

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!')
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!