fork download
  1. # -*- coding:utf-8 -*-
  2.  
  3. import urllib
  4. import urllib2
  5. import re
  6. import sys
  7. import time
  8. import threading
  9.  
  10. OUTPUT_ENCODE = 'shift-jis'
  11. YAHOO_ENCODE = 'utf-8'
  12. POLLING_PAGE = 'http://v...content-available-to-author-only...o.jp/theme/106'
  13. POSTURL = 'http://v...content-available-to-author-only...o.jp/poll'
  14. UA = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7'
  15. INTERVAL = 1
  16.  
  17. def GetCookie():
  18. header = {'User-Agent':UA}
  19. req = urllib2.Request(POLLING_PAGE,None,header)
  20. res = urllib2.urlopen(req)
  21. cookie = res.info()['Set-Cookie'].split(';')[0]
  22. return cookie
  23.  
  24. def GetCrumb(cookie):
  25. term = ur'<input type="hidden" name="crumb" value=".*">'
  26.  
  27. header = {
  28. 'User-Agent':UA,
  29. 'Cookie':cookie
  30. }
  31. req = urllib2.Request(POLLING_PAGE,None,header)
  32. res = urllib2.urlopen(req)
  33. html = res.read().decode(YAHOO_ENCODE)
  34. m = re.search(term,html)
  35. if(m is None):
  36. print(u'しばらくたってからまた来てね☆'.encode(OUTPUT_ENCODE))
  37. return None
  38. return m.group(0)[41:-2]
  39.  
  40. def Postyahoo(cookie):
  41. crumb = GetCrumb(cookie)
  42. if(crumb is None):
  43. return
  44.  
  45. header = {'Cookie':cookie}
  46. data = {
  47. "pollChoice[]":'9',
  48. "pollId":'16',
  49. "pageId":'106',
  50. "pageType":'theme',
  51. "page":'1',
  52. "crumb":crumb,
  53. 'submit':u'投票する'.encode(YAHOO_ENCODE)
  54. }
  55. data = urllib.urlencode(data)
  56. req = urllib2.Request(POSTURL, data, header)
  57. res = urllib2.urlopen(req)
  58. if(u'投票ありがとうございました' in res.read().decode(YAHOO_ENCODE)):
  59. print(u'投票完了'.encode(OUTPUT_ENCODE))
  60. else:
  61. print(u'何かがおかしい'.encode(OUTPUT_ENCODE))
  62.  
  63. def post():
  64. while(True):
  65. cookie = GetCookie()
  66. Postyahoo(cookie)
  67. time.sleep(INTERVAL)
  68.  
  69. def main():
  70. print('PLEASE USE THIS PROGRAM AT YOUR OWN RISK.')
  71. threadnum = 0
  72. interv = 0
  73. try:
  74. threadnum = int(raw_input(u'スレッドを立てる数を入力(よく分からなければそのままEnter):'.encode(OUTPUT_ENCODE)))
  75. except ValueError:
  76. threadnum = 1
  77. try:
  78. interv = int(raw_input(u'投稿間隔を入力(sec):'.encode(OUTPUT_ENCODE)))
  79. except ValueError:
  80. interv = 1
  81.  
  82. INTERVAL = interv
  83. tlst = []
  84. for i in range(threadnum):
  85. tlst.append(threading.Thread(target=post))
  86. for i in tlst:
  87. i.start()
  88.  
  89. if __name__ == '__main__':
  90. main()
  91.  
Runtime error #stdin #stdout #stderr 0.08s 12264KB
stdin
Standard input is empty
stdout
PLEASE USE THIS PROGRAM AT YOUR OWN RISK.
�X���b�h�𗧂Ă鐔���(�悭������Ȃ���΂��̂܂�Enter):
stderr
Traceback (most recent call last):
  File "prog.py", line 90, in <module>
  File "prog.py", line 74, in main
EOFError: EOF when reading a line