python服务代理ip

import requests

要访问的目标页面

#targetUrl = “http://proxy.abuyun.com/switch-ip”
#targetUrl = “http://proxy.abuyun.com/current-ip”

代理服务器

proxyHost = “http-dyn.abuyun.com”
proxyPort = “9020”

代理隧道验证信息

proxyUser = " xxxxxxx"
proxyPass = "xxxxxx "

proxyMeta = “http://%(user)s:%(pass)s@%(host)s:%(port)s” % {
“host” : proxyHost,
“port” : proxyPort,
“user” : proxyUser,
“pass” : proxyPass,
}

proxies = {
“http” : proxyMeta,
“https” : proxyMeta,
}

url = ‘http://2019.ip138.com/ic.asp’ #查看自己的当前ip
resp = requests.get(url,proxies = proxies)
resp.encoding=‘gb2312’
rst = resp.text
print(rst)

############################################
import requests
from fake_useragent import FakeUserAgent
ua=FakeUserAgent()
ua.ie #ie浏览器
ua.chrome #谷歌浏览器
ua.firefox #火狐浏览器
ua.random #随机浏览器
headers={‘user_Agent’: ua.chrome}
url = ‘https://blog.csdn.net/’
rep = requests.get(url,headers=headers)
print(rep.status_code)

你可能感兴趣的:(python服务代理ip)