代理IP的简单应用
一、代理IP获取
代理IP一般有两种方式获取:
1、代理网站上的免费公用IP
这一步就是通过爬取大量网上的公用IP,建立一个初步的代理IP池,因为是免费的,所以很多IP都不能用,所以要做一个筛查的功能,就是通过访问指定网页,来看返回的网页状态码是否成功。

2、购买
私密代理12元1000个一天,每个IP平均存活时长1~5分钟
Source Code
import requests
# 目标网址
target_url = ['***']
# 每次只提取一个IP
for i in range(1000):
try:
api_url = "http://dps.kdlapi.com/api/getdps?orderid=908816899692073&num=1&signature=1s0koqizcza7lmb8netrhwnyci2fedj8&pt=1&showtype=1"
proxy_ip = requests.get(api_url)
ip_host = str(proxy_ip.content).split("'")[1]
print(ip_host)
username = "********"#你的用户名
password = "********"#你的密码
proxies = {
"http": "http://{}:{}@{}/".format(username, password, ip_host),
"https": "https://{}:{}@{}/".format(username, password, ip_host)
}
headers = {"Accept-Encoding": "Gzip", }
while True:
for url in target_url:
r = requests.get(url,proxies=proxies, headers=headers, timeout = 3) #
print('【{}】【{}】'.format(i, target_url.index(url)),r.status_code)
except:
continue
3294



被折叠的 条评论
为什么被折叠?



