|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +""" |
| 5 | +利用代理IP刷点赞票(89IP) |
| 6 | +author: gxcuizy |
| 7 | +date: 2021-03-25 |
| 8 | +""" |
| 9 | + |
| 10 | +import requests |
| 11 | +import time |
| 12 | +from bs4 import BeautifulSoup |
| 13 | + |
| 14 | + |
| 15 | +class EightNine(object): |
| 16 | + def __init__(self): |
| 17 | + # 点赞接口地址 |
| 18 | + self.api_url = 'http://638140.szyuansl.com/topfirst.php?g=Wap&m=Vote&a=ticket' |
| 19 | + # 点赞请求参数 |
| 20 | + self.post_param = {'zid': '11883', 'vid': '237', 'token': 'WMFAUktmdTwiHtTe'} |
| 21 | + # 接口请求头信息 |
| 22 | + self.header = { |
| 23 | + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1320.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2875.116 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63010200)', |
| 24 | + 'Content-Type': 'application/x-www-form-urlencoded' |
| 25 | + } |
| 26 | + # 代理IP地址 |
| 27 | + self.proxies = {} |
| 28 | + # 超时时间 |
| 29 | + self.time_out = 20 |
| 30 | + |
| 31 | + def get_proxies_ip(self, ip_url): |
| 32 | + """获取代理IP""" |
| 33 | + ip_request = requests.get(url=ip_url) |
| 34 | + html_content = ip_request.content |
| 35 | + soup = BeautifulSoup(html_content, 'html.parser') |
| 36 | + # IP列表 |
| 37 | + tr_list = soup.select('.layui-table tbody tr') |
| 38 | + ip_list = [] |
| 39 | + for tr in tr_list: |
| 40 | + td_info = tr.select('td') |
| 41 | + ip_host = td_info[0].text.strip() |
| 42 | + ip_port = td_info[1].text.strip() |
| 43 | + ip_base = '//' + ip_host + ':' + ip_port |
| 44 | + ip_list.append(ip_base) |
| 45 | + return ip_list |
| 46 | + |
| 47 | + def print_msg(self, msg=''): |
| 48 | + """打印信息""" |
| 49 | + now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) |
| 50 | + print('[' + now_time + '] ' + msg) |
| 51 | + |
| 52 | + def run(self): |
| 53 | + """执行程序""" |
| 54 | + while True: |
| 55 | + # 获取前7页 |
| 56 | + page_list = range(1, 7) |
| 57 | + for page in page_list: |
| 58 | + request_url = 'https://www.89ip.cn/index_' + str(page) + '.html' |
| 59 | + # 获取IP地址 |
| 60 | + ip_list = self.get_proxies_ip(request_url) |
| 61 | + for ip_info in ip_list: |
| 62 | + self.proxies = { |
| 63 | + 'http': 'http:' + ip_info, |
| 64 | + 'https': 'https:' + ip_info |
| 65 | + } |
| 66 | + try: |
| 67 | + # 发送post请求 |
| 68 | + request = requests.post(url=self.api_url, data=self.post_param, headers=self.header, |
| 69 | + proxies=self.proxies, timeout=self.time_out) |
| 70 | + response_text = request.text |
| 71 | + self.print_msg(response_text) |
| 72 | + except Exception as err_info: |
| 73 | + # 异常信息 |
| 74 | + self.print_msg(str(err_info)) |
| 75 | + |
| 76 | + |
| 77 | +# 程序主入口 |
| 78 | +if __name__ == "__main__": |
| 79 | + obj = EightNine() |
| 80 | + obj.run() |
0 commit comments