クリスマスプレゼント?
ついかっとなってやった。どう考えてもルール違反だと思うので自己責任で。
!/usr/bin/env python # -*- coding: utf-8 -*- import urllib,urllib2 import cookielib import re class Travian: def __init__(self): pass # loginの値を一回login.php見て取ってくる def getLoginId(self): data = urllib2.urlopen("http://s3.travian.jp/login.php") a = data.read() reg = re.compile('<input type=\"hidden\" name=\"login\" value=\"(.*?)\">') idGroup = reg.search(a) id = idGroup.group(1) print "id",id return id def signIn(self): postdata = {} postdata['w'] = "" postdata['login'] = self.getLoginId() postdata['e8790fb'] = self.user['user'] postdata['e88b613'] = self.user['pass'] postdata['ebd1bf1'] = "" #postdata['source'] = s en_post_data = urllib.urlencode(postdata) cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) # ログイン/cookie取得 r = opener.open("http://s3.travian.jp/dorf1.php",en_post_data) print r.read() return opener t = Travian() t.user = {} t.user['user'] = "username" t.user['pass'] = "password" t.signIn()
実行結果
id 1230113037 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <title>Travian jp3</title> <link rel=stylesheet type="text/css" href="new.css?w"> <link rel=stylesheet type="text/css" href="unx.css"> <script src="unx.js?w" type="text/javascript"></script> <meta http-equiv="cache-control" content="max-age=0"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="imagetoolbar" content="no"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body onload="start()"><div id="ltop1"><div id="ltop5"><a href="dorf1.php"><img id="n1" src="img/un/a/x.gif" title="村の概観"></a><a href="dorf2.php" ><img id="n2" src="img/un/a/x.gif" title="村の中心"></a><a href="karte.php"><img id="n3" src="img/un/a/x.gif" title="地図"></a><a href="statistiken.p hp"><img id="n4" src="img/un/a/x.gif" title="統計"></a><img id="n5" src="img/un/l/m4.gif" usemap="#nb"><a href="plus.php"><img id="lplus1" src="img/j p/a/plus.gif" width="80" height="100" title="plusメニュー"></a></div></div><map name="nb"><area shape=rect coords="0,0,35,100" href="berichte.php" ti tle="レポート"><area shape=rect coords="35,0,70,100" href="nachrichten.php" title="メッセージ"></map><div id="lmidall"><div id="lmidlc"><div id="llef t"> <a href="http://www.travian.jp/"><img class="logo" src="img/jp/a/travian1.gif"></a><table id="navi_table" cellspacing="0" cellpadding="0"> <tr> <td class="menu"> <a href="http://www.travian.jp/">ホームページ</a> <a href="#" onClick="return Popup(0,0);">説明</a>
以下省略