python3 实现的人人影视网站自动签到


Posted in Python onJune 19, 2016

这是一个自动化程度较高的程序,运行本程序后会从chrome中读取cookies用于登录人人影视签到,
并且会自动添加一个windows 任务计划,这个任务计划每天下午两点会执行本程序进行签到。

sys.executable == 'C:\\Python34\\pythonw.exe'
使用pythonw 执行.py 不会弹出命令行窗口。

以system权限执行的程序不能访问网络,/ru 参数后的值改为administrators或者users

import os
import sys
import subprocess
import sqlite3
import time
import requests
from win32.win32crypt import CryptUnprotectData

def 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 0

def 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()
Python 相关文章推荐
分享给Python新手们的几道简单练习题
Sep 21 Python
机器学习python实战之决策树
Nov 01 Python
Python字典的核心底层原理讲解
Jan 24 Python
对python条件表达式的四种实现方法小结
Jan 30 Python
pandas 使用均值填充缺失值列的小技巧分享
Jul 04 Python
在python中画正态分布图像的实例
Jul 08 Python
pycharm通过anaconda安装pyqt5的教程
Mar 24 Python
Python pip安装第三方库实现过程解析
Jul 09 Python
python中取绝对值简单方法总结
Jul 24 Python
Python机器学习三大件之一numpy
May 10 Python
详解Python中的进程和线程
Jun 23 Python
Python机器学习实战之k-近邻算法的实现
Nov 27 Python
python3实现暴力穷举博客园密码
Jun 19 #Python
在阿里云服务器上配置CentOS+Nginx+Python+Flask环境
Jun 18 #Python
Python中使用装饰器来优化尾递归的示例
Jun 18 #Python
举例讲解Python面向对象编程中类的继承
Jun 17 #Python
浅谈python为什么不需要三目运算符和switch
Jun 17 #Python
python运行时间的几种方法
Jun 17 #Python
从局部变量和全局变量开始全面解析Python中变量的作用域
Jun 16 #Python
You might like
解析php中curl_multi的应用
2013/07/17 PHP
PHP中使用sleep函数实现定时任务实例分享
2014/08/21 PHP
PHP SPL标准库之数据结构栈(SplStack)介绍
2015/05/12 PHP
php中str_pad()函数用法分析
2017/03/28 PHP
Ubuntu 16.04中Laravel5.4升级到5.6的步骤
2018/12/07 PHP
php+Ajax处理xml与json格式数据的方法示例
2019/03/04 PHP
ExtJs之带图片的下拉列表框插件
2010/03/04 Javascript
jQuery Clone Bug解决代码
2010/12/22 Javascript
ASP.NET jQuery 实例2 (表单中使用回车在TextBox之间向下移动)
2012/01/13 Javascript
jquery showModelDialog的使用方法示例详解
2013/11/19 Javascript
jquery提交form表单时禁止重复提交的方法
2014/02/13 Javascript
Angular发布1.5正式版,专注于向Angular 2的过渡
2016/02/18 Javascript
JavaScript中0和""比较引发的问题
2016/05/26 Javascript
利用JS提交表单的几种方法和验证(必看篇)
2016/09/17 Javascript
js实现html table 行,列锁定的简单实例
2016/10/13 Javascript
JavaScript排序算法动画演示效果的实现方法
2016/10/18 Javascript
BootStrap Validator对于隐藏域验证和程序赋值即时验证的问题浅析
2016/12/01 Javascript
node.js实现的装饰者模式示例
2017/09/06 Javascript
Windows安装Node.js报错:2503、2502的解决方法
2017/10/25 Javascript
Vue.set() this.$set()引发的视图更新思考及注意事项
2018/08/30 Javascript
layer.open的自适应及居中及子页面标题的修改方法
2019/09/05 Javascript
解决在layer.open中使用时间控件laydate失败的问题
2019/09/11 Javascript
python进阶教程之文本文件的读取和写入
2014/08/29 Python
Python单元测试unittest的具体使用示例
2018/12/17 Python
Python匿名函数/排序函数/过滤函数/映射函数/递归/二分法
2019/06/05 Python
python3 xpath和requests应用详解
2020/03/06 Python
Python多线程正确用法实例解析
2020/05/30 Python
在终端启动Python时报错的解决方案
2020/11/20 Python
python statsmodel的使用
2020/12/21 Python
详解H5本地储存Web Storage
2017/07/03 HTML / CSS
什么是用户模式(User Mode)与内核模式(Kernel Mode) ?
2015/09/07 面试题
数控专业应届生求职信
2013/11/27 职场文书
教师实习自我鉴定
2013/12/11 职场文书
电台编导求职信
2014/05/06 职场文书
学习焦裕禄精神践行三严三实心得体会
2014/10/13 职场文书
2016年小学生寒假家长评语
2015/10/10 职场文书