绯月论坛自动点广告,自动抽奖的python实现

python code:

# !/usr/bin/env python

import  codecs
import  urllib
import  cookielib
import  urllib2
from  time  import  strftime

params
= { ' jumpurl ' : ' / ' , ' step ' : ' 2 ' , ' cktime ' : ' 311536000 ' , ' lgt ' : ' 0 ' , ' pwuser ' : 'USERNAME ' , ' pwpwd ' : 'PASSWORD ' }
url
= ' http://bbs.2dgal.com/ '
encoding
= ' gbk '
outputencoding
= ' utf-8 '

print  strftime( " %Y-%m-%d %H:%M:%S " )

opener
= urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.LWPCookieJar()))
params
= urllib.urlencode(params)
f
= opener.open(url + ' login.php ' ,params)
data
= f.read()
f.close()
udata
= codecs.decode(data,encoding)
if  udata.find( ' refresh ' ) > 0:
    
print   ' login\n\n '
else :
    exit()
f
= opener.open(url + ' diy_ad_move.php?id=2 ' )
data
= f.read()
f.close()
print  codecs.encode(codecs.decode(data,encoding),outputencoding)
print   ' \n\n '

f
= opener.open(url + ' kf_fw_ig_one.php ' , ' one=1&submit=%B3%E9%BD%B1%3C2%3E ' )
data
= f.read()
f.close()
print  codecs.encode(codecs.decode(data,encoding),outputencoding)
print   ' \n\n '

 

如需定时自动执行,像这样将它加入crontab或计划任务

   2 0   *    *   *     *   /root/2dgal.py >> /var/log/2dgal/2dgal.log

 

非英文用户名还要处理一下编码问题,不过我懒了,而且手上没非英文帐号,就不管了

你可能感兴趣的:(python)