zoukankan      html  css  js  c++  java
  • 使用SAEPython在虾米网自动签到

    丑陋的代码,请谅解。对于我来说糙快猛是第一位的

    使用了新浪SAE下的python环境。其中内嵌了bottle框架。然后还用了cron定时任务服务。

    使用了http://huxuan.org的自动签到代码,非常感谢!

    页面代码,单文件:

    index.wsgi

    # -*- coding:utf-8 -*- 
    from bottle import Bottle, run
    
    import sae
    import urllib2
    import urllib
    import cookielib
    import re
    
    app = Bottle()
    
    
    @app.route('/')
    def hello():
        return "Hello, world! - Bottle"
    @app.route('/xiamicheckin' , method='GET')
    def xiami():
       
        email = "xxxxx@qq.com"#请填写账号
        password = "1234567"#请填写密码
        # Init
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
        urllib2.install_opener(opener)
        # Login
        login_url = 'http://www.xiami.com/web/login'
        login_data = urllib.urlencode({'email':email, 'password':password, 'LoginButton':'登陆',})
        login_headers = {'Referer':'http://www.xiami.com/web/login', 'User-Agent':'Opera/9.60',}
        login_request = urllib2.Request(login_url, login_data, login_headers)
        login_response = urllib2.urlopen(login_request).read()
        
        # Checkin
        checkin_pattern = re.compile(r'<a class="check_in" href="(.*?)">')
        checkin_result = checkin_pattern.search(login_response)
        checkin_url = 'http://www.xiami.com' + checkin_result.group(1)    
        checkin_headers = {'Referer':'http://www.xiami.com/web', 'User-Agent':'Opera/9.60',}
        checkin_request = urllib2.Request(checkin_url, None, checkin_headers)
        checkin_response = urllib2.urlopen(checkin_request).read()
        #return checkin_response
        return "done"
    application = sae.create_wsgi_app(app)

    config.yaml文件(配置cron定时任务)

    ---
    name: yourappid
    version: 1
    cron:
      - description: xiami
        url: xiamicheckin
        schedule: 21 7 * * *
    
    ...

    一些解释和注意:

    1.SAE的 cron使用get方式触发任务。所以被触发的页面应接受get方式。

    @app.route('/xiamicheckin' , method='GET')

    2.bottle中,如果未指明method,则默认为get。

    @app.route('/')

    3.SAE的cron文档有问题,其中示例代码:

      #该BUG已被修复

    name: crontest 
    version: 1 
    cron: 
    - description: cron_test 
    url: /cron/make 
    schedule: "*/5 * * * *" 

    应改为

    name: crontest 
    version: 1 
    cron: 
    - description: cron_test 
    url: /cron/make 
    schedule:  */5 * * * *

     

  • 相关阅读:
    所以怎样实现列表点击整行上下移动?
    高德标签label样式
    ubuntu上安装ldap以及phpLdapAdmin步骤(php连接管理ldap简化版实现)
    ubuntu 16.04下快速安装PHP环境
    open LDAP以及phpLDAPadmin入门ubuntu 16.04
    “微信之父”张小龙:微信背后的产品观
    所以Ubuntu如何清理不必要的文件?
    百度无人驾驶Apollo的dreamview的demo运行
    新手用的git配置命令
    php+redis实现消息队列
  • 原文地址:https://www.cnblogs.com/bitspace/p/2521545.html
Copyright © 2011-2022 走看看