一、豌豆http
import requests
targetUrl = "http://myip.ipip.net"
api_url = 'api的网址'
a = requests.get(api_url).text
httpProxyServer = str(a).strip()
print(httpProxyServer)
proxies = {
"http": 'http://{}'.format(httpProxyServer),
"https": 'http://{}'.format(httpProxyServer),
}
print("request ==============================")
resp = requests.get(targetUrl, proxies=proxies)
print(resp.status_code)
print(resp.text)
二、芝麻http
api_url = "api的网址"
proxy_ip = requests.get(api_url).text
username = "账号"
password = "密码"
proxies = {
"http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip},
"https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip}
}
res = requests.get(url, headers=headers, proxies=proxies)
print(res.text)