python 에서 http 를 처리하는 방벙에는 기본적으로 제공하는
urllib, urllib2 모듈을 이용하는 방법도 있지만
request 모듈을 이용하면 좀더 편리하게 처리할 수 있다.
pip install requests
pip를 이용하여 설치후 사용한다.
#! -*- coding:utf-8 -*- import requests r = requests.get('http://comic.naver.com/webtoon/detail.nhn?titleId=22027&no=1&weekday=wed') print(r.text) print(r.headers) print(r.encoding) print(r.cookies) print('-------------------') # header 를 이용 headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0'} r1 = requests.get('http://imgcomic.naver.net/webtoon/22027/1/20140324120405_6fe13380c15aab68b6172d4c33e9b9dc_IMAG01_1.jpg', headers=headers) print(r1) print(r1.status_code) print(r1.raise_for_status())
http://docs.python-requests.org/en/master/
반응형
'python' 카테고리의 다른 글
[python] 파이썬은 정말로 느린가? (0) | 2016.06.07 |
---|---|
[개념] 파이썬 종류, 장단점, 속도에 대한 변명 (0) | 2016.05.16 |
[os] 디렉토리의 특정파일의 파일명 변경하기 (0) | 2016.03.23 |
[urllib / http]http로 웹에서 파일 다운로드 하기 (3) | 2016.03.05 |
[xml] xml 파싱하기 (0) | 2016.02.16 |