簡體   English   中英

輸入不使用Mechanize / Ruby表單的網站的登錄信息

[英]Entering login information for a site that doesn't use forms with Mechanize/Ruby

我需要登錄到站點以運行一些腳本。 使用Nokogiri進行機械化看起來非常適合該任務,但是由於輸入字段不在表單中(agent.page.forms.first產生nil),因此我很難輸入登錄信息:

    <div class="loginform" id="login_form">
      <div>
        <input type="text" id="loginname" tabindex="1"/>
      </div>
      <div>
        <input type="password" id="password" tabindex="2"/>
        <input type="text" id="password_text" style="display:none;"/>
      </div>
      <div class="signin"><a href="javascript:void(0);" class="sp" id="login_submit_btn"></a>
      </div>
    </div>

是否可以通過某種方式導航到輸入元素(它們是頁面上的唯一元素),然后提交我的用戶名和密碼進行登錄? 如果Mechanize無法執行此類操作,是否有其他選擇? 非常感謝。

我認為您最好檢查一下整個來源(包括javascript),該網站如何與您建立聯系。 我認為這應該是HTTP POST請求...,並使用它直接登錄,而無需通過GET請求解析主頁,而是使用Mechanize post method

agent = Mechanize.new
url = 'http://website.com/hidden_login_page.php'
page = agent.post(url, {"login" => "foo", "password" => "bar"})

希望它也有幫助。

我最近遇到這樣的問題。 在機械化中嘗試以下操作:

page.field_with(:name => "loginname").value = "foo"
page.field_with(:name => "password").value = "bar"

希望這可以幫助。

干杯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM