這是一個自動化程度較高的程序,運行本程序后會從chrome中讀取cookies用于登錄人人影視簽到,
并且會自動添加一個windows 任務計劃,這個任務計劃每天下午兩點會執行本程序進行簽到。
sys.executable == 'C://Python34//pythonw.exe'
使用pythonw 執行.py 不會彈出命令行窗口。
以system權限執行的程序不能訪問網絡,/ru 參數后的值改為administrators或者users
import osimport sysimport subprocessimport sqlite3import timeimport requestsfrom win32.win32crypt import CryptUnprotectDatadef getcookiefromchrome(host='.oschina.net'): cookiepath=os.environ['LOCALAPPDATA']+r"/Google/Chrome/User Data/Default/Cookies" sql = "select host_key,name,encrypted_value from cookies where host_key='%s'" % host with sqlite3.connect(cookiepath) as conn: cu = conn.cursor() cookies = {name:CryptUnprotectData(encrypted_value)[1].decode() for host_key,name,encrypted_value in cu.execute(sql).fetchall()} print(cookies) return cookies#運行環境windows 2012 server python3.4 x64 pywin32 chrome 50 """ #windows 版chrome Cookies文件為一個sqlite3數據庫, #chrome 33以后的版本的cookies的value都加密存在encrypted_value中, #需要使用win32crypt的CryptUnprotectData 對encrypted_value進行解密, win32crypt是pywin32的一部分,需要安裝最新的pywin32模塊 """#getcookiefromchrome()#getcookiefromchrome('.baidu.com')def sign(): zmcookie = getcookiefromchrome('.zimuzu.tv') url = 'http://www.zimuzu.tv/user/login/getCurUserTopInfo' requests.get(url,cookies=zmcookie).text rs = requests.get('http://www.zimuzu.tv/user/sign',cookies=zmcookie).text.split('/n') info = [r for r in rs if "三次登錄時間" in r] time_=time.strftime("%c") with open("zmlog.txt","a+") as f: f.write(time_ + " :" ) f.writelines(info) f.write("/n/n")tn='zmautosign'def run(ar=sys.argv): if len(ar)==1: sign() if not intask(): addtask() #添加任務計劃 elif len(ar)>1 and ar[1].lower()=="-task": sign()def intask(tn=tn,ar=sys.argv[0]): txt=subprocess.getoutput('schtasks /query |find "%s"' % tn) if tn in txt: return 1 else: return 0def addtask(tn=tn,ar=sys.argv[0]): cmd='schtasks /create /F /ru Administrators /tn "%s" /sc daily /st 14:00:00 /tr "%s %s -task"' % (tn,sys.executable,ar) subprocess.call(cmd,shell=1)os.chdir(sys.path[0])run()新聞熱點
疑難解答
圖片精選