Python语言代码示例
发布时间:2022-07-03 00:46
Python requests
import requests
-
targetURL = "http://myip.ipip.net"
proxyAddr = "219.151.125.106:31615"
authKey = "895314XY"
password = "24D6YB309ZCB"
-
# 账密模式
proxyUrl = "http://%(user)s:%(password)s@%(server)s" % {
"user": authKey,
"password": password,
"server": proxyAddr,
}
-
proxies = {
"http": proxyUrl,
"https": proxyUrl,
}
-
resp = requests.get(targetURL, proxies=proxies)
print(resp.text)
Python aiohttp
import aiohttp,asyncio
-
targetURL = "http://myip.ipip.net"
proxyAddr = "219.151.125.106:31615"
authKey = "895314XY"
password = "24D6YB309ZCB"
-
# 账密模式
proxyUrl = "http://%(user)s:%(password)s@%(server)s" % {
"user": authKey,
"password": password,
"server": proxyAddr,
}
-
async def entry():
conn = aiohttp.TCPConnector(ssl=False)
-
async with aiohttp.ClientSession(connector=conn) as session:
async with session.get(targetURL, proxy=proxyUrl) as resp:
body = await resp.read()
print(resp.status)
print(body)
-
loop = asyncio.get_event_loop()
loop.run_until_complete(entry())
loop.run_forever()
Python urllib2、urllib
import urllib2
-
targetURL = "http://myip.ipip.net"
proxyAddr = "219.151.125.106:31615"
authKey = "895314XY"
password = "24D6YB309ZCB"
-
proxyUrl = "http://%(user)s:%(password)s@%(server)s" % {
"user": authKey,
"password": password,
"server": proxyAddr,
}
-
proxies = urllib2.ProxyHandler({
"http": proxyUrl,
"https": proxyUrl,
})
-
opener = urllib2.build_opener(proxies)
urllib2.install_opener(opener)
resp = urllib2.urlopen(targetURL).read()
-
print(resp)
相关文章