python刷票

这两天帮助小侄女刷票

写了个脚本,如下:

#!/usr/bin/python
import  http.cookiejar, urllib
from urllib.error import URLError, HTTPError
import json,time
#投票页面url
indexUrl="http://show.lilyenglish.com/index.php/content?sid=273"

#投票请求url
voteUrl="http://show.lilyenglish.com/index.php/content/do_vote"
#投票请求参数
parameters={
"id": 273
}

#500次
for i in range(1,500):
    #cookie持有
    cj = http.cookiejar.CookieJar()
    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
    #proxy=urllib.request.ProxyHandler({'sock5':'183.207.228.9:80'})
    #opener.add_handler(proxy)
    urllib.request.install_opener(opener)
    req=urllib.request.Request(indexUrl)
    resp= urllib.request.urlopen(req)
    #print(resp.getheader("Set-Cookie"))
    #print(resp.getheaders())
    #print(cj)
    #设置参数
    parameters['userAgent']=str(i)+"Mozilla/5.0  sdsdsi (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) dsd Chrome/31.0.1650.63 Safari/537.36 SE 2.X MetaSr 1.0"
    parameterencode=urllib.parse.urlencode(parameters)
    #print(parameterencode)
    parameterencode=parameterencode.encode('UTF-8')
    #print(parameterencode)
    #request=urllib.request.Request(voteUrl,parameterencode)
    resp2= opener.open(voteUrl,parameterencode)
    #resp2= urllib.request.urlopen(voteUrl,parameterencode)
    print("请求完毕,{0}".format(resp2.status))
    jsonData = json.loads(resp2.read().decode('utf-8'))
    print(i,jsonData)
    time.sleep(3)



  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值