【问题标题】:Retrieve the source code of a url using pycurl and a port number?使用 pycurl 和端口号检索 url 的源代码?
【发布时间】:2015-08-05 06:32:01
【问题描述】:
有什么方法可以检索 url 源代码并将其存储在字符串中,前提是在 pycurl 模块中定义了特定端口,以便它适用于代理网络。
平台 - ubuntu 或任何其他 linux 发行版
【问题讨论】:
标签:
python
linux
python-2.7
ubuntu
pycurl
【解决方案1】:
使用此代码获取 url 的来源
from StringIO import StringIO
import pycurl
url = 'http://www.google.com/'
storage = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
c.close()
content = storage.getvalue()
print content