【问题标题】: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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 2013-02-18
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多