Last active
September 11, 2023 11:34
-
-
Save eternnoir/7670741 to your computer and use it in GitHub Desktop.
Area11論壇 LoginBot. python filename.py id pw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2.7 | |
import cookielib | |
import sys | |
import urllib | |
from BeautifulSoup import BeautifulSoup | |
import mechanize | |
class A_11_loginBot(object): | |
def __init__(self,id,pw,action=""): | |
self._id = id | |
self._pw = pw | |
self._action = action | |
self._url = "http://bbs.area-11.com/member.php?mod=logging&action=login" | |
self._br = mechanize.Browser() | |
# Cookie Jar | |
cj = cookielib.LWPCookieJar() | |
self._br.set_cookiejar(cj) | |
# Browser options | |
self._br.set_handle_equiv(True) | |
self._br.set_handle_redirect(True) | |
self._br.set_handle_referer(True) | |
self._br.set_handle_robots(False) | |
# Follows refresh 0 but not hangs on refresh > 0 | |
self._br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) | |
# User-Agent (this is cheating, ok?) | |
self._br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] | |
def login(self): | |
self._br.open(self._url) | |
self._br.select_form(nr=1) | |
self._br.form['username'] = self._id | |
self._br.form['password'] = self._pw | |
return self._br.submit() | |
def getBrowser(self): | |
return self._br | |
if __name__ == '__main__': | |
print 'Start' | |
id_ = sys.argv[1] | |
pw = sys.argv[2] | |
if len(sys.argv) > 3: | |
pid = int(sys.argv[3]) | |
else: | |
pid = None | |
print 'Try to Login' | |
bot = A_11_loginBot(id_,pw) | |
bot.login() | |
print bot.getBrowser().response().read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment