使用某个开源项目的API获得的ip,API链接为API在这里,为了检测是否可用,我使用获得的ip用requests访问了ip查询网站
但是,发现我查询到的ip并没有变化
下面是我的代码
麻烦大家帮忙看下
import requests
from lxml import etree
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
}
url = 'https://ip.cn/'
# 下面的网站是用来获取代理ip的API
ip_url = 'http://proxy.w2n1ck.com:9090/random'
ip = {'http' : 'http://'+requests.get(ip_url).text}
print(ip)
response = requests.get(url, headers=headers, proxies=ip, timeout=10).text
html = etree.HTML(response)
# 提取页面显示的ip
res = html.xpath('//*[@id="result"]/div/p[1]/code/text()')
print(res)
你访问的是 https,要配置 https 代理:
如果代理服务器支持 https 就可以代理成功