파이썬에서 빠르게 HTTP GET하고 싶습니다
조회수 15109회
발생하는 문제 및 실행환경
파이썬에서 제일 빠르게 HTTP GET하는 방법은 뭘까요?
get한 뒤에 contents = url.get("http://example.com/foo/bar")
같은 문자열을 찾아내려고 하는데 제가 get하는 방법을 모릅니다.
httplib이나 urilib를 쓰면 된다고 하던데 영어를 못해서 그런지 잘 모르겠더군요..
일단 열어야지 뭘 찾을건데 열수 없으니 거 참..
어떻게 써야하는지 아시는분은 알려주시면 감사하겠습니다
덧) 저는 파이썬 2쓰고 있습니다
1 답변
-
Python 2.x:
import urllib2 urllib2.urlopen("http://example.com/foo/bar").read()
Python 3.x:
import urllib.request urllib.request.urlopen("http://example.com/foo/bar").read()
2.x ,3.x 둘다 :
import requests r = requests.get("http://www.naver.com") print(r.status_code) print(r.headers) print(r.content)
댓글 입력