2015-12-20 62 views
0

這裏是我想登錄的Python:使用Python

<FORM NAME="form" METHOD="POST" ACTION="./memberlogin" onsubmit="this.onsubmit= function(){return false;}"> 


<table class='loginTbl' border='1' align="center" cellspacing='3' cellpadding='3' width='60%'> 
    <input type="hidden" name="hdnrequesttype" value="1" /> 
    <thead> 
    <tr> 
    <td colspan='3' align="middle" class='loginHead'>Login</td> 
    </tr> 
    </thead> 

    <tbody class='loginBody'> 

    <tr> 
    <td class='loginBodyTd1' nowrap="nowrap">Employee ID</td> 
    <td class='loginBodyTd2'><input type='text' name='txtmemberid' id='txtmemberid' value='' class='loginTextBox' size='30' maxlength='8'/></td> 
    <td class='loginBodyTd3' rowspan='2'><input type="submit" class="goclearbutton" value=" Go "></td> 
    </tr><input type='hidden' name='txtmemberpwd' id='txtmemberpwd' value='' /> 

    </tbody> 

    <tfoot> 
    <tr> 
     <td colspan='3' class='loginFoot'> 
      <font class='loginRed'>New Visitor?</font> 

      <a href="mailto:[email protected]?subject=New Registration&body=New Registartion Request">Send</a> your registration request to library ! 

      </td> 
     </tr> 
    </tfoot> 

    </table> 
    </form> 

我已經做了谷歌的研究一下,發現我已經使用請求頁面的HTML提交表單上的網站對象或urllib或機械化。所有這些都很混亂,請告訴我最簡單的方法。

回答

0

爲方便起見,我建議您使用PhantomJS

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 

phantom = webdriver.PhantomJS() 

phantom.get('http://www.mypage.com.br') 

form_consultation = phantom.find_element_by_id('txtmemberid') 
form_consultation.send_keys('1234') 
phantom.find_element_by_class_name('goclearbutton').click() 
0

使用要求和化網頁瀏覽器庫登陸,她的示例代碼[Source]

import requests 
import webbrowser 


# Fill in your details here to be posted to the login form. 
payload = { 
    'inUserName': 'username', # put the name field that you get form the html on the left as the key , 
           # and the value that you want to put in, to the right 

    'inUserPass': 'password' # inUserPass is obtained from the HTML form 
} 

# Use 'with' to ensure the session context is closed after use. 
with requests.Session() as s: 
    p = s.post('LOGIN_URL', data=payload) # LOGIN_URL is where the form is submitted 
    # print the html returned or something more intelligent to see if it's a successful login page. 

    with open("requests_results1.html", "wb") as f: 
     f.write(p.content)  # write the html to a local file and opens it so you can see the output after the login. 
    webbrowser.open("requests_results1.html") 

    # Open a new page which can only be accessed after successfull login 
    r = s.get('A protected web page url') 
    print r.text 
     # etc... 

評論,如果您有任何問題。