python 模块pycurl的简单使用,抓取url链接数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#!/usr/bin/python # -*- coding: utf-8 -*-
import sys import pycurl import cStringIO
#解决编译器运行,UnicodeEncodeError: 'ascii' codec can't encode characters in position reload(sys) sys.setdefaultencoding( "utf-8" )
buf = cStringIO.StringIO() c = pycurl.Curl() c.setopt(c.URL, 'http://www.kaixin001.com/rest/rest.php') c.setopt(c.WRITEFUNCTION, buf.write) c.perform() print buf.getvalue() buf.close()
|
近期评论