python实现街旁自动签到

# -*- coding: UTF-8 -*-
import mechanize
import cookielib
import sys
from BeautifulSoup import BeautifulSoup

class CheckIn:
    def __init__(self,url):
        self.br = mechanize.Browser()
        self.ID = "your ID"
        self.pwd= "your pwd"
        self.url= url
    def setCookie(self,user,password):
        self.ID = user
        self.pwd= password
        
    def setBrowser(self):
        ###设置一些参数,因为是模拟客户端请求,所以要支持客户端的一些常用功能,比如gzip,referer等
        self.br.set_handle_equiv(True)
        #self.br.set_handle_gzip(True)
        self.br.set_handle_redirect(True)
        self.br.set_handle_referer(True)
        self.br.set_handle_robots(False)
        self.br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
        #设置header
        self.br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11')]
    def login(self):
        response = self.br.open(self.url)
        self.br.select_form(nr=0)
        self.br.form['user'] = self.ID
        self.br.form['pwd'] = self.pwd
        self.br.submit()
        print "login successfully"
    def checkin(self):
        self.br.follow_link(text = '签到')
        self.br.select_form(nr = 0)
        self.br.form['q'] = 'your addr'
        self.br.submit()
        self.br.follow_link(text='
your addr
') self.br.select_form(nr=0) self.br.form['status'] = 'test' self.br.submit(nr=1) #这是隐私和同步 self.br.select_form(nr=0) #仅自己可见 self.br.find_control(type="checkbox").items[0].selected=True #设置并返回 self.br.submit(nr=1) #签到 self.br.select_form(nr=0) self.br.submit(nr=0) def printPage(self): checkin_content = self.br.response().read() file = open("C:\\Users\\Yaomian\\Desktop\\3.html", "wb") file.write(checkin_content)def main(): Jiepang = CheckIn("http://jiepang.com/m/") Jiepang.setBrowser() Jiepang.login() Jiepang.checkin() Jiepang.printPage()if __name__ == "__main__": main()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值