2010-04-08 23 views
1

我想以編程方式登錄到https://www.t-mobile.com/。我的第一個想法是用機械化來提交登錄表單:獲取機械化來處理來自任意POST的Cookie(以編程方式登錄到網站)

alt text http://dl.dropbox.com/u/2792776/screenshots/2010-04-08_1440.png

然而,事實證明,這甚至不是一個真正的形式。相反,當您單擊「登錄」時,某些JavaScript會抓取字段的值,動態創建一個新表單並提交它。

「登錄」 按鈕,HTML:

<button onclick="handleLogin(); return false;" class="btnBlue" id="myTMobile-login"><span>Log in</span></button> 

handleLogin()功能:

function handleLogin() { 
    if (ValidateMsisdnPassword()) { // client-side form validation logic 
     var a = document.createElement("FORM"); 
     a.name = "form1"; 
     a.method = "POST"; 
     a.action = mytmoUrl; // defined elsewhere as https://my.t-mobile.com/Login/LoginController.aspx 
     var c = document.createElement("INPUT"); 
     c.type = "HIDDEN"; 
     c.value = document.getElementById("myTMobile-phone").value; // the value of the phone number input field 
     c.name = "txtMSISDN"; 
     a.appendChild(c); 
     var b = document.createElement("INPUT"); 
     b.type = "HIDDEN"; 
     b.value = document.getElementById("myTMobile-password").value; // the value of the password input field 
     b.name = "txtPassword"; 
     a.appendChild(b); 
     document.body.appendChild(a); 
     a.submit(); 
     return true 
    } else { 
     return false 
    } 
} 

我可以用Net::HTTP#post_form張貼表單數據https://my.t-mobile.com/Login/LoginController.aspx模擬這種形式提交,但我不知道如何將生成的cookie導入機械化,以便我可以繼續在登錄時刮取可用的UI。

任何ide如?

+5

這是直接** TOS違規**。 「您同意不使用任何機器人,蜘蛛,刮板或其他自動化手段或任何手動過程訪問,監控或複製網站上的任何內容或信息;」 https://www.t-mobile.com/Templates/Popup.aspx?WT.z_unav=ftr__useterms&PAsset=Ftr_Ftr_TermsOfUse&print=true – 2010-04-09 13:47:31

+5

@ rlb.usa:嗯......服務條款說你不能「訪問......任何內容......使用任何手動過程「......我會說,除非您不以任何方式使用服務,否則這將很難遵守。 :) – retracile 2010-04-09 13:53:57

+2

@retracile:當你訪問t-mobile的網站時,你顯然有責任通過他們的服務條款來關閉你的大腦。 – voyager 2010-04-09 13:59:41

回答

1

我經常使用FireFox HttpFox擴展來找出這些問題到底發生了什麼。

3

你可以使用類似的東西來登錄並保存cookie,這樣你就不必再做一次了。當然,您需要提出自己的邏輯來直接發佈它,但這是我使用Mechanize的內置cookie_jar方法來保存cookie的方式。

if !agent.cookie_jar.load('cookies.yml') 
    page = agent.get('http://site.com') 

    form = page.forms.last 
    form.email = 'email' 
    form.password = 'password' 

    page = agent.submit(form) 

    agent.cookie_jar.save_as('cookies.yml') 
end