Python3.x:代理ip刷点赞

声明:仅供为学习材料,不允许用作商业用途;

一,功能:

 针对某网站对企业自动刷点赞;

 网站:https://best.zhaopin.com/

二,步骤:

1,获取代理ip(代理ip地址:http://www.xicidaili.com/nn);

2,模拟浏览器打开点赞页面;

3,模拟点赞事件,并传递参数;

 参数获取:根据浏览器的开发者工具,跟踪点赞事件;对应的“Network”可以看到相关的表头信息,其中的From Data就是参数信息;

三、代码:

# python3
# 功能:对https://best.zhaopin.com/中的某企业刷点赞
import re
import random
import sys
import time
import datetime
import threading
from random import choice
import requests
import bs4 # 设置user-agent列表,每次请求时,可在此列表中随机挑选一个user-agnet
user_agent = [
"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",
] # 国内高匿代理IP,返回当前页的所有ip
def get_ip_list():
#获取代理IP(取当前页的ip列表,每页100条ip)
url = "http://www.xicidaili.com/nn"
headers = { "Accept":"text/html,application/xhtml+xml,application/xml;",
"Accept-Encoding":"gzip, deflate, sdch",
"Accept-Language":"zh-CN,zh;q=0.8,en;q=0.6",
"Referer":"http://www.xicidaili.com",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"
}
r = requests.get(url,headers=headers)
soup = bs4.BeautifulSoup(r.text, 'html.parser')
data = soup.table.find_all("td")
# 匹配规则需要用浏览器的开发者工具进行查看
# 匹配IP:<td>61.135.217.7</td>
ip_compile= re.compile(r'<td>(\d+\.\d+\.\d+\.\d+)</td>')
# 匹配端口:<td>80</td>
port_compile = re.compile(r'<td>(\d+)</td>')
# 获取所有IP,返回的是数组[]
ip = re.findall(ip_compile,str(data))
# 获取所有端口:返回的是数组[]
port = re.findall(port_compile,str(data))
# 组合IP+端口,如:61.135.217.7:80
return [":".join(i) for i in zip(ip,port)] # 打开页面。执行点赞行为
def do_dz(code=0,ips=[]):
#点赞,如果代理IP不可用造成点赞失败,则会自动换一个代理IP后继续点赞
try:
# 随机选取一个ip
ip = choice(ips)
except:
return False
else:
proxies = {
"http":ip,
}
headers_ = {
"Accept":"*/*",
"Accept-Encoding":"gzip, deflate, sdch",
"Accept-Language":"zh-CN,zh;q=0.8,en;q=0.6",
"Referer":"https://best.zhaopin.com/",
"User-Agent":choice(user_agent),
}
# 用浏览器的开发者工具跟踪点赞事件传输的参数值
datas = {'bestid': 6030, 'source': 'best'}
try:
# 点赞网址
url_dz = "https://best.zhaopin.com/API/Vote.ashx"
# 执行点赞行为(发送请求)
r_dz = requests.post(url_dz,headers=headers_,data=datas,proxies=proxies)
except requests.exceptions.ConnectionError:
print("Connection Error")
if not ips:
print("not ip")
sys.exit()
# 删除不可用的代理IP
if ip in ips:
ips.remove(ip)
# 重新请求URL
get_url(code,ips)
else:
# 获取当前时间
date = datetime.datetime.now().strftime('%H:%M:%S')
print(u"第%s次 [%s] [%s]:投票%s (剩余可用代理IP数:%s)" % (code,date,ip,r_dz.text,len(ips))) if __name__ == '__main__':
ips = []
# python3把xrange()与rang()e整合为一个range()
for i in range(5000):
# 每隔1000次重新获取一次最新的代理IP
if i % 1000 == 0:
ips.extend(get_ip_list())
# 启用线程,隔2秒产生一个线程
t1 = threading.Thread(target=do_dz,args=(i,ips))
t1.start()
# time.sleep的最小单位是毫秒
time.sleep(2)

作者:整合侠
链接:http://www.cnblogs.com/lizm166/p/8242193.html
来源:博客园
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Python3.x:代理ip刷点赞的更多相关文章

  1. Python3.x:代理ip刷评分

    Python3.x:代理ip刷评分 声明:仅供为学习材料,不允许用作商业用途: 一,功能: 针对某网站对企业自动刷评分: 网站:https://best.zhaopin.com/ 二,步骤: 1,获取 ...

  2. 使用不同代理IP刷票的脚本---requests

    投票功能限制刷票是通过限制单个IP的投票次数实现的,所以写了个脚本用于测试此功能. #-*- coding=utf-8 -*- ''' 功能:此脚本用于用不同的IP刷票 作者:Elle 最后修改日期: ...

  3. 【python3】如何建立爬虫代理ip池

    一.为什么需要建立爬虫代理ip池 在众多的网站防爬措施中,有一种是根据ip的访问频率进行限制的,在某段时间内,当某个ip的访问量达到一定的阀值时,该ip会被拉黑.在一段时间内被禁止访问. 这种时候,可 ...

  4. Python3网络爬虫(四):使用User Agent和代理IP隐藏身份《转》

    https://blog.csdn.net/c406495762/article/details/60137956 运行平台:Windows Python版本:Python3.x IDE:Sublim ...

  5. Python3网络爬虫(3):使用User Agent和代理IP隐藏身份

    Python版本: python3 IDE: pycharm2017.3.3 一.为何要设置User Agent 有一些网站不喜欢被爬虫访问,所以会检测对象,如果是爬虫程序,他就会不让你访问,通过设置 ...

  6. Python3.x:免费代理ip的批量获取并入库

    Python3.x:免费代理ip的批量获取并入库 一.简介 网络爬虫的世界,向来都是一场精彩的攻防战.现在许多网站的反爬虫机制在不断的完善,其中最令人头疼的,莫过于直接封锁你的ip.但是道高一尺魔高一 ...

  7. Python3.x:获取代理ip以及使用

    Python3.x:获取代理ip以及使用 python爬虫浏览器伪装 #导入urllib.request模块 import urllib.request #设置请求头 headers=("U ...

  8. scrapy怎么设置带有密码的代理ip base64.encodestring不能用 python3.5,base64库里面的encodestring()被换成了什么?

    自己写爬虫时买的代理ip有密码,在网上查了都是下面这种: 1.在Scrapy工程下新建"middlewares.py": import base64 # Start your mi ...

  9. python3 selenium模块Chrome设置代理ip的实现

    python3 selenium模块Chrome设置代理ip的实现 selenium模块Chrome设置代理ip的实现代码: from selenium import webdriver chrome ...

随机推荐

  1. 如何激励用户为你的app评分?

    如何激励用户为你的app评分? 2014-04-10 16:21 编辑: suiling 分类:营销推广 来源:CocoaChina  0 7247 应用设计应用评分 招聘信息: IOS兼职 深圳创业 ...

  2. CH5101 LCIS【线性dp】

    5101 LCIS 0x50「动态规划」例题 描述 熊大妈的奶牛在小沐沐的熏陶下开始研究信息题目.小沐沐先让奶牛研究了最长上升子序列,再让他们研究了最长公共子序列,现在又让他们研究最长公共上升子序列了 ...

  3. 巨蟒python全栈开发-第11阶段 devops-git入门1

    大纲 1.git命令初识 2.git reset与diff 3.git区域总结 4.git 远程仓库 5.git stash 1.git命令初识 2.git reset与diff 3.git区域总结 ...

  4. java面试基础题------》Java 中的final关键字有哪些用法

    (1)修饰类:表示该类不能被继承: (2)修饰方法:表示方法不能被重写: (3)修饰变量:表示变量只能一次赋值以后值不能被修改(常量).

  5. c# 下三角实现 九九乘法口诀表

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Hell ...

  6. Bootstrap CSS组组件架构的设计思想

    w AO模式 Append Overwrite 附加重写

  7. tomcat启动报错:Injection of autowired dependencies failed

    Error creating bean with name 'backPrintPaperController': Injection of autowired dependencies failed ...

  8. 如何使用 libtorch 实现 LeNet 网络?

    如何使用 libtorch 实现 LeNet 网络? LeNet 网络论文地址: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf

  9. PHP error_log 新认知

    //error_log 简介及使用方法 //  error_log("消息","类型","路径"); //message   //type  ...

  10. 文字识别的google的库 tesseract

    https://github.com/tesseract-ocr/tesseract https://github.com/tesseract-ocr/tessdata             字体识 ...