2010-01-27 77 views
1

的HTML看起來像下面或者你可以在這裏找到它http://www.vbulletin.org/forum/index.php如何登錄到vBulletin 3.6使用機械化(紅寶石)

<!-- login form --> 
     <form action="login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)"> 

     <script type="text/javascript" src="clientscript/vbulletin_md5.js?v=3612"></script> 
        <table cellpadding="0" cellspacing="1" border="0"> 
        <tr> 
         <td class="smallfont" align="left"><label for="navbar_username">User Name</label></td> 
         <td class="smallfont" align="left" colspan="2"><label for="navbar_password">Password</label></td> 
        </tr> 
        <tr> 

         <td><input type="text" class="button" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" /></td>   
         <td><input type="password" class="button" name="vb_login_password" id="navbar_password" size="10" accesskey="p" tabindex="102" /></td> 
         <td class="smallfont" align="left" valign="middle"><input type="submit" class="button" value="Log in" tabindex="103" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" /> 
          <label for="cb_cookieuser_navbar"> 
          <input type="checkbox" name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" />Save?</label> 
          <input type="hidden" name="s" value="" /> 
<input type="hidden" name="securitytoken" value="1cbc0286417d97b4eb43ee0b0c2b54e7c615e5b8" /> 
          <input type="hidden" name="do" value="login" /> 
          <input type="hidden" name="vb_login_md5password" /> 

          <input type="hidden" name="vb_login_md5password_utf" /></td> 
        </tr> 
        </table> 
     </form> 
     <!--/login form --> 

我下面的代碼不能正常工作。在我看來,我必須提交一些隱藏的領域。有誰知道

  • 如何提交隱藏字段?
  • 如果我需要提交名稱和值或只是其中之一?
  • 如何登錄到vBulleting V3.6

一些文本,顯示如下文字作爲代碼

require 'rubygems' 
require 'mechanize' 
agent = WWW::Mechanize.new 
page = agent.get("http://www.vbulletin.org/forum/index.php") 

login_form = page.form_with(:action => 'login.php?do=login') 
login_form['vb_login_username'] = 'username' 
login_form['vb_login_password]'] = 'password' 
page = agent.submit login_form 

#Display welcome message if logged in 
puts page.parser.xpath("/html/body/div/table/tr/td[2]/div/div").xpath('text()').to_s.strip 

output = File.open("login.html", "w") {|f| f.write(page.parser.to_html) } 

回答

2

vBulletin需要密碼,而不是實際的密碼的MD5。所以如果你捕捉你的瀏覽器發出的內容,你可以使用該值。或者你必須使用md5庫(未測試)來創建任何密碼的md5哈希。

require 'rubygems' 
require 'mechanize' 


agent = WWW::Mechanize.new 

page = agent.get("http://www.vbulletin.org/forum/index.php") 

login_form = page.form_with(:action => 'login.php?do=login') 

login_form['vb_login_username'] = 'user name' 
login_form['vb_login_password'] = '' 
login_form['vb_login_md5password_utf'] = 'md5 hash from the password' 
login_form['vb_login_md5password'] = 'md5 hash from the password' 

page = agent.submit login_form 

#Display welcome message if logged in 
puts page.parser.xpath("/html/body/div/table/tr/td[2]/div/div").xpath('text()').to_s.strip 

output = File.open("login.html", "w") {|f| f.write(page.parser.to_html) }