[python]代码库
# coding=utf-8
# 刷企业直通车,一人一票刷
import re
import sys
import time
import datetime
import threading
from random import choice
import requests
import bs4
from selenium import webdriver
def get_ip():
"""获取代理IP"""
url = 'http://http.tiqu.alicdns.com/getip3?num=100&type=1&pro=330000&city=330400&yys=0&port=1&time=1&ts=0&ys=0&cs=0&lb=6&sb=,&pb=4&mr=1®ions=&gm=4'
r = requests.get(url)
ip_compile = re.compile('\d+\.\d+\.\d+\.\d+:\d+') # 匹配IP
# port_compile = re.compile(r'<td>(\d+)</td>') # 匹配端口
ip = re.findall(ip_compile, str(r.text)) # 获取所有IP
# port = re.findall(port_compile, str(data)) # 获取所有端口
# return [":".join(i) for i in zip(ip, port)] # 组合IP+端口,如:115.112.88.23:8080
return ip
# 设置 user-agent列表,每次请求时,可在此列表中随机挑选一个user-agnet
uas = [
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0; Baiduspider-ads) Gecko/17.0 Firefox/17.0",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9b4) Gecko/2008030317 Firefox/3.0b4",
"Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; BIDUBrowser 7.6)",
"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; Touch; LCJB; rv:11.0) like Gecko",
]
def get_url(code=0, ips=[]):
"""
投票
如果因为代理IP不可用造成投票失败,则会自动换一个代理IP后继续投
"""
print(code)
try:
ip = ips[code]
except:
return False
else:
opt = webdriver.ChromeOptions() # 创建浏览器
opt.set_headless() # 无窗口模式
opt.add_argument('--proxy-server=%s' % ip)
driver = webdriver.Chrome(options=opt) # 创建浏览器对象
# driver.maximize_window() #最大化窗口
hz_url = "http://ztc.jx96871.com:9082/message/goMessage.do?d5f4634d-5022-4935-9g20-312800ac264c" # 某投票网站的地址,这里不用真实的域名
hz_url2 = "http://ztc.jx96871.com:9082/policysearch/list?F_PFID=d5f4634d-5022-4935-9g20-312800ac264c"
driver.get(hz_url) # 打开网页
time.sleep(3) # 加载等待
driver.get(hz_url2) # 打开网页
time.sleep(3) # 加载等待
# check = driver.find_element_by_xpath('/html/body/div/section/div[1]/div[1]').text
driver.close()
# if check == "政策层级":
# num = num + 1
# driver.close()
# date = datetime.datetime.now().strftime('%H:%M:%S')
# print(u"第%s次 [%s] [%s]:成功%s (剩余可用代理IP数:%s)" % (code, date, ip, num, len(ips)))
ips = []
ips.clear()
ips.extend(get_ip())
print(u"IP数量:%s" % len(ips))
for i in range(80):
# 启用线程,隔1秒产生一个线程,可控制时间加快投票速度 ,time.sleep的最小单位是毫秒
t1 = threading.Thread(target=get_url, args=(i, ips))
t1.start()
time.sleep(8)
初级程序员
by: 伟大的梦想 发表于:2021-02-20 16:10:32 顶(0) | 踩(0) 回复
可以用吗?
回复评论