【用Python写爬虫】获取html的方法【二】:使用pycurl
2008-06-04 09:40
1021 查看
# Pycurl参考地址:http://pycurl.sourceforge.net/
# Pycurl下载地址:http://pycurl.sourceforge.net/download/pycurl-7.18.1.tar.gz
# -*-coding: UTF-8 -*-
importpycurl
importStringIO
defgetURLContent_pycurl(url):
c = pycurl.Curl()
c.setopt(pycurl.URL,url)
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
# 代理
#c.setopt(pycurl.PROXY, 'http://11.11.11.11:8080')
#c.setopt(pycurl.PROXYUSERPWD, 'aaa:aaa')
c.perform()
returnb.getvalue()
url = 'http://blog.csdn.net'
content =getURLContent_pycurl(url)
print content
# Pycurl下载地址:http://pycurl.sourceforge.net/download/pycurl-7.18.1.tar.gz
# -*-coding: UTF-8 -*-
importpycurl
importStringIO
defgetURLContent_pycurl(url):
c = pycurl.Curl()
c.setopt(pycurl.URL,url)
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
# 代理
#c.setopt(pycurl.PROXY, 'http://11.11.11.11:8080')
#c.setopt(pycurl.PROXYUSERPWD, 'aaa:aaa')
c.perform()
returnb.getvalue()
url = 'http://blog.csdn.net'
content =getURLContent_pycurl(url)
print content
相关文章推荐
- 【用Python写爬虫】获取html的方法【一】:使用urllib
- 【用Python写爬虫】获取html的方法【四】:使用urllib下载文件
- 【用Python写爬虫】获取html的方法【一】:使用urllib
- 【用Python写爬虫】获取html的方法【三】:使用cPAMIE
- 【用Python写爬虫】获取html的方法【五】:利用Twisted框架之client.getPage
- [python爬虫]获取html中文乱码时的方法
- Python开发中爬虫使用代理proxy抓取网页的方法示例
- python爬虫由浅入深6--基于bs4库的HTML内容的查找方法
- python使用Flask框架获取用户IP地址的方法
- Python爬虫项目,获取所有网站上的新闻,并保存到数据库中,解析html网页等(未完待续)
- 使用python 获取进程pid号的方法
- 使用Python获取并处理IP的类型及格式方法
- python爬虫get和post方法的使用以及cookie
- 【Python3.6爬虫学习记录】(六)urllib详细使用方法(header,代理,超时,认证,异常处理)
- HTML中使用python屏蔽一些基本功能的方法
- Python使用爬虫爬取静态网页图片的方法详解
- python爬虫(20)使用真实浏览器打开网页的两种方法
- Java爬虫学习:使用HtmlUnit获取html页面
- Python使用pyh生成HTML文档的方法示例