-
产品介绍
-
购买指南
-
使用指南
-
快速入门
-
电脑如何使用代理IP
-
手机如何使用代理IP
-
浏览器如何使用代理IP
-
软件如何使用代理IP
-
代码调用方式示例
-
常见问题
Python语言代码示例
发布时间:2021-12-08 16:15
Python requests
import requests
targetURL = "https://myip.top"
proxyAddr = "您的代理IP:端口"
authKey = "请改成您的Key"
password = "请改成您的AuthPwd"
# 账密模式
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 = "https://myip.top"
proxyAddr = "您的代理IP:端口"
authKey = "请改成您的Key"
password = "请改成您的AuthPwd"
# 账密模式
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 = "https://myip.top"
proxyAddr = "您的代理IP:端口"
authKey = "请改成您的Key"
password = "请改成您的AuthPwd"
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)
相关文章
微信客服