这两天帮助小侄女刷票
写了个脚本,如下:
#!/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