In Python, the normal fetch data uses the URLLIB2 module directly:
' http://fanyi.baidu.com/ ' == stream.read () Print cont
If we want to go to the HTTP proxy, we can also use URLLIB2, do not need to reference other modules:
' Https://clients5.google.com/pagead/drt/dn/dn.js ' = urllib2. Proxyhandler ({'http':'127.0.0.1:1080' = = opener.open (URL) print f.read ()
If we want to use the SOCKS5 proxy, we need another module sockes, socket, we can get through the PIP install socksipy, (I am the Windows system, also need another module, pip install Win_inet_pton) It is recommended to download the installation package directly to the Python installation directory, switch to the corresponding directory, execute the python setup.py install installation, is really dead to the wall of the big celestial, and then add the socket code on the module that needs the agent:
" 127.0.0.1 " the = Socks.socksocket
The complete code is as follows:
The added code begins with
" 127.0.0.1 " the = socks.socksocket
= Urllib2.urlopen ('https://clients5.google.com/pagead/drt/dn/dn.js') print Steam.read ()
Using the Requests module, we also add the socket code before the requests, and the subsequent HTTP request does not change, or the original logic:
The added code begins with
Import win_inet_ptonimport socketimport socksimport requestsip='localhost' socks.socksocket//= End of code added
' Https://clients5.google.com/pagead/drt/dn/dn.js ' print requests. Get (URL). text
Related:
Github:https://github.com/mitsuhiko/python-geoip/issues/4
NONO
Source: http://www.cnblogs.com/diligenceday/
Enterprise website: http://www.idrwl.com/Xiamen Lighting the Future network technology
Open Source Blog: Http://www.github.com/sqqihao
QQ: 287101329
: 18101055830
Xiamen Lighting Future Network Technology Co., Ltd., is the best application of Xiamen, small program, website, the public number development company
Python fetches data, Python uses SOCKS proxy to fetch data