`

python 抓取网页

阅读更多
#urllib2
wp = urllib2.urlopen(self.url)
content = wp.read();

 

pycurl

        	buf = cStringIO.StringIO()
         
        	c = pycurl.Curl()
        	c.setopt(c.URL,self.url)
        	c.setopt(c.WRITEFUNCTION, buf.write)
        	c.perform()
         	
        	content =  buf.getvalue()
        	buf.close()        
    
    
    	   
            jc = json.loads(content)

 

# 设置超时时间为30秒  
import socket  
socket.setdefaulttimeout(30) 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics