圆月山庄资源网 Design By www.vgjia.com

1.[文件] DakeleSign.py ~ 4KB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'poppy'
'''
dakele bbs sigin
'''
import sys
import urllib2
import urllib
import requests
import cookielib
import json
from pyquery import PyQuery as pq
import logging
logging.basicConfig(level=logging.DEBUG)
reload(sys)
sys.setdefaultencoding("utf8")
class Dakele(object):
  def __init__(self,name,password):
    self.name = name
    self.password = password
    self.cj = cookielib.LWPCookieJar()
    self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
    urllib2.install_opener(self.opener)
  def _getHeaders(self):
    headers = {}
    headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
    #headers['Host']='www.dakele.com'
    headers['Connection']='keep-alive'
    headers['Cache-Control']='max-age=0'
    headers['Accept-Language']='zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4'
    #headers['Accept-Encoding']='gzip, deflate, sdch'
    headers['Accept']='text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    return headers
  def login(self):
    '''登录网站'''
    logging.debug(u'正在登陆 username : %s password : %s' %(self.name,self.password))
    logging.debug(u'headers is : %s' % self._getHeaders())
    loginparams = {'product': 'bbs','surl': r'http://bbs.dakele.com/','username': self.name,'password':self.password,'remember':'0'}
    logging.debug(u'loginparams is : %s' % loginparams)
    req = urllib2.Request( r'http://passport.dakele.com/logon.do', urllib.urlencode(loginparams), headers=self._getHeaders())
    response = urllib2.urlopen(req)
    self.operate = self.opener.open(req)
    thePage = response.read()
    result = json.loads(thePage)
    return result['redirect']
  def login_bbs(self,url):
    '''登录bbs网站'''
    logging.debug( 'start bbs login : %s ' % url)
    req = urllib2.Request(url,headers=self._getHeaders())
    response = urllib2.urlopen(req)
    self.operate = self.opener.open(req)
    thePage = response.read()
    #print thePage
  def _say(self,html):
    d = pq(html)
    s_action = d("#qiandao").attr("action")
    if s_action:
      s_formhash = d("#qiandao input[name=formhash]").attr("value")
      s_qdxq = d("#qiandao input[name=qdxq]").attr("value")
      s_qdmode = '1'
      loginparams = {'formhash':s_formhash,'qdxq':s_qdxq,'qdmode': s_qdmode,'todaysay':u'可乐社区是我家,我们大家都爱Ta...'}
      req = urllib2.Request( r'http://bbs.dakele.com/'+s_action, urllib.urlencode(loginparams), headers=self._getHeaders())
      response = urllib2.urlopen(req)
      self.operate = self.opener.open(req)
      thePage = response.read()
    else:
      logging.debug( u'今天已经签到过...')
  def sign(self,url):
    logging.debug( 'start bbs sign : %s' % url)
    req = urllib2.Request(url,headers=self._getHeaders())
    response = urllib2.urlopen(req)
    self.operate = self.opener.open(req)
    thePage = response.read()
    self._say(thePage)
if __name__ == '__main__':
  userlogin = Dakele('username','password')
  bbs_loginurl = userlogin.login()
  userlogin.login_bbs(bbs_loginurl)
  userlogin.sign('http://bbs.dakele.com/dsu_paulsign-sign.html');

总结

以上所述实小编给大家介绍的Python实现某论坛自动签到功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

标签:
python,论坛,签到,python,自动签到

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?