大家好,又见面了,我是你们的朋友全栈君。
[Python] 纯文本查看 复制代码import threading #导入多线程库
import requests #导入requests库模拟访问
import time #导入时间库
from lxml import etree
def pnw(num=1): #定义一个循环的函数
while 0 < int(num): # 当0
# 设置请求头
headers = {‘User-Agent’: “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1”}
# 依次遍历生成2-99
for i in range(2, 100):
url = “https://www.kuaidaili.com/free/inha/” + str(i) + “/” # 爬取的免费ip
response = requests.get(url, headers=headers).text # 获得网页文本数据
response_xpath = etree.HTML(response) # 转换为xpath可用结构
ips = response_xpath.xpath(‘//*[@id=”list”]/table/tbody/tr/td[1]/text()’) # ip的信息
dks = response_xpath.xpath(‘//*[@id=”list”]/table/tbody/tr/td[2]/text()’) # 端口的信息
https = response_xpath.xpath(‘//*[@id=”list”]/table/tbody/tr[2]/td[4]/text()’) # http信息
for ip, dk, http in zip(ips, dks, https):
proxy = “http://” + ip + “:” + dk # 拼接ip
print(proxy)
proxies = {“http”: proxy}
url = “http://url.cn/5z0Sqsw” #发给我的注册链接
res = requests.get(url,proxies=proxies) #用requests的get()函数来访问 设置ip
print(res) #打印查看状态 Response [200]代表成功
url = “https://asd8654.com/api_fusion/Notice/getMarqueeNotice” #随便找了个post网址,没找到注册的post
res = requests.post(url,proxies=proxies) #用requests的post()函数访问 设置ip
print(res) #打印查看状态 Response [200]代表成功
time.sleep(5) #休息5s
if __name__ == ‘__main__’:
t1 = threading.Thread(target=pnw, args=(“1”)) #第一个线程
t2 = threading.Thread(target=pnw, args=(“2”)) #第二个线程
t3 = threading.Thread(target=pnw, args=(“3”)) #以此类推
t4 = threading.Thread(target=pnw, args=(“4”))
t5 = threading.Thread(target=pnw, args=(“5”))
t6 = threading.Thread(target=pnw, args=(“6”))
t7 = threading.Thread(target=pnw, args=(“7”))
t8 = threading.Thread(target=pnw, args=(“8”))
t9 = threading.Thread(target=pnw, args=(“9”))
t1.start() #启动第一个线程
t2.start() #以此类推
t3.start()
t4.start()
t5.start()
t6.start()
t7.start()
t8.start()
t9.start()
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/162212.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...