파이썬 HTTP 302의 hwp 파일을 다운받고 싶습니다
조회수 1648회
우선 목표는 comcat사이트의 hwp 파일을 다운로드 하는것입니다.
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)
이렇게 다운로드 하면 30KB의 HTML이 받아지더군요.. 302 리다이렉션이란걸 찾아서 Location을 반환해주는 requests의 allow_redirects를 찾았습니다.. 그래서 다르게도 짜보았는데
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)
이렇게도 다운로드 하면 30KB의 HTML이 받아지더군요.. 처음302일때 url과 200일때 url은 서로 다른것은 확실한데 ㅠㅠ 혹시 좋은 조언 있을까요..
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
자문 자답... requests, allow_redirects 후 urlretrieve가 아닌 with open('filename.hwp', 'wb') as f로 새로운 파일을 생성해서 f.write(res.content)하니 잘 되네요!!
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력