I want to download the hwp file of Python HTTP 302

Asked 1 years ago, Updated 1 years ago, 122 views

The first goal is to download the hwp file of comcat site.

dl_name = '1'
dl_path = http://www.comcbt.com/xe/?module=file&act=procFileDownload&file_srl=2651934&sid=57058e18dd8b3d3bcfe0907f7c7ba155&module_srl=555664

req.urlretrieve(response.url, path + '/' + name + '/' + dl_name)

When I download it like this, I get 30KB of HTML. I found the 302 redirection and found the allow_redirects of requests that return the location. So I made it differently

dl_name = '1'
dl_path = http://www.comcbt.com/xe/?module=file&act=procFileDownload&file_srl=2651934&sid=57058e18dd8b3d3bcfe0907f7c7ba155&module_srl=555664

res = requests.get(dl_path, allow_redirects=True)

req.urlretrieve(response.url, path + '/' + name + '/' + dl_name)

If I download it like this, I can get 30KB of HTML. Url at 302 and url at 200 are definitely different from each other when it is 302 for the first time and url is different when it is 200 for sure Do you have any good advice?

python3 urllib

2022-09-22 19:34

1 Answers

Ask yourself... requests, after allow_redirects Create a new file with open('filename.hwp', 'wb') as f instead of urlretrieve and f.It works well with write(res.content)!


2022-09-22 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.