友善交流技术...
python 访问URL
上一篇 /
下一篇 2012-02-16 14:39:48
/ 个人分类:开发代码
import pycurl
import StringIO
import re
url = "http://www.baidu.com/"
crl = pycurl.Curl()
crl.setopt(pycurl.VERBOSE,1)
crl.setopt(pycurl.FOLLOWLOCATION, 1)
crl.setopt(pycurl.MAXREDIRS, 5)
crl.fp = StringIO.StringIO()
crl.setopt(pycurl.URL, url)
crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
crl.perform()
#只打印出<body>部分
p=re.compile(r'(<body>.*)(.*</body>)', re.DOTALL)
#p=re.compile(r'(<a href=\".*\">)', re.DOTALL)
m=p.search(crl.fp.getvalue())
if m:
print m.group(0)
收藏
举报
TAG: