본문 바로가기
프로그래밍

[Python] pycurl 예제

by dladbru 2015. 6. 4.

urllib , pycurl , requests로 벤치마킹한 결과 장점으로는 매우빠른 속도가 있다. 


#!/usr/bin/python
from base64 import *
import StringIO
import pycurl
import time

print "Start!"
curl = pycurl.Curl()


attackurl="http://www.naver.com"


SC = StringIO.StringIO()

header= ["Cookie:data=1234"]
            
curl.setopt(pycurl.URL, attackurl)
curl.setopt(pycurl.HTTPHEADER, header)
curl.setopt(pycurl.WRITEFUNCTION, SC.write)
curl.setopt(pycurl.FOLLOWLOCATION,1)
try:
    curl.perform()
    html = SC.getvalue()
    print html
    SC.close()
except Exception, e:
    print "Exception : %s"% e


반응형

댓글