# -*- 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='
') 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()your addr
python实现街旁自动签到
最新推荐文章于 2022-07-14 14:36:46 发布