Skip to content

Instantly share code, notes, and snippets.

@zxc111
Created March 22, 2014 13:59
Show Gist options
  • Save zxc111/9707553 to your computer and use it in GitHub Desktop.
Save zxc111/9707553 to your computer and use it in GitHub Desktop.
s1挂机脚本
# -*- encoding: utf8 -*-
import urllib2
import urllib
from cookielib import CookieJar
import pdb
import time
def check_process():
import subprocess
import sys
process_name = sys.argv[0]
if subprocess.check_output(["ps", "-ef"]).count("python %s" % process_name) == 1:
return True
else:
return False
def login(name, password):
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)
url = "http://bbs.saraba1st.com/2b/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1"
data = {
"fastloginfield": "username",
"username": name,
"password": password,
"quickforward": "yes",
"handlekey": "ls",
}
data_encoded = urllib.urlencode(data)
respense = opener.open(url, data_encoded)
respense.read()
#pdb.set_trace()
return opener
def run(opener_with_cookie, name):
url = "http://bbs.saraba1st.com/2b/forum.php"
while 1:
if opener_with_cookie.open(url).read().find(name) == -1:
print u"cookie失效什么的".encode("utf8")
break
else:
print u"努力挂机中".encode("utf8")
time.sleep(30)
if __name__ == "__main__":
name = ""
password = ""
if check_process() == False:
exit()
while 1:
print u"登录...".encode("utf8")
run(login(name, password), name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment