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)
网络投票大都采用post方法,因此我们可以分析post的url,对具体的post参数进行分析,通过requests模块,进行提交就行了。需要注意的是大部分网站可能存在ip地址限制,或者浏览器限制等情况,所以需要设计代理和ua列表进行投票,避免被屏蔽。试了半天才弄明白是怎么回事。是中英文的问题。你在votes.txt里的冒号放的是中文冒号:,而你在程序里split用的是英文的冒号:, 结果split后得到的内容是一个,而不是两个。这样你将一个内容赋值给两个就会出现
ValueError: need more than 1 value to unpack
你可以打印print my_love
这样就知道为什么了。