Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pycurl和端口号检索url的源代码?_Python_Linux_Python 2.7_Ubuntu_Pycurl - Fatal编程技术网

Python 使用pycurl和端口号检索url的源代码?

Python 使用pycurl和端口号检索url的源代码?,python,linux,python-2.7,ubuntu,pycurl,Python,Linux,Python 2.7,Ubuntu,Pycurl,有没有办法检索url源代码并将其存储在字符串中,前提是pycurl模块中定义了一个特定的端口,以便它可以用于代理网络。 平台-ubuntu或任何其他linux发行版使用此代码获取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.W

有没有办法检索url源代码并将其存储在字符串中,前提是pycurl模块中定义了一个特定的端口,以便它可以用于代理网络。
平台-ubuntu或任何其他linux发行版使用此代码获取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

向我们展示到目前为止您已经尝试了什么?对于大多数代理,您需要一个代理主机名和一个端口。