如何用python实现网络上的自动投票功能

Python014

如何用python实现网络上的自动投票功能,第1张

网络投票大都采用post方法,因此我们可以分析post的url,对具体的post参数进行分析,通过requests模块,进行提交就行了。需要注意的是大部分网站可能存在ip地址限制,或者浏览器限制等情况,所以需要设计代理和ua列表进行投票,避免被屏蔽。

def vote(stra):

yesstr=['yes','y']

nostr=['no','n']

abstainedstr=['abstained','a']

count=0

yescount=0

stra=stra.replace(',',' ')

for i in stra.split():

lowerstr=i.lower()

if lowerstr in yesstr:

yescount+=1

count+=1

elif lowerstr in nostr:

count+=1

if yescount==count:

return 'proposal passes unanimously'

if yescount*1.0/count>=2.0/3.0:

return 'proposal passes with super majority'

if yescount*1.0/count>=0.5:

return 'proposal passes with simple majority'

return 'proposal fails'

if __name__=='__main__':

stra=raw_input('Enter the yes,no,abstained votes one by one and the press enter:\n')

print vote(stra)