python : Submit a form on website using python

标签 python web-scraping urllib2 mechanize

这是我要登录的页面的 html

<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:admin@libsys.co.in?subject=New Registration&body=New Registartion Request">Send</a> your registration request to library !

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

   </table>
   </form>

我对谷歌做了一些研究,发现我必须使用请求对象或 urllib 或 Mechanize 。所有这些都非常令人困惑,请告诉我最简单的方法。

最佳答案

为方便起见,我建议您使用 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()

关于 python : Submit a form on website using python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34381612/

相关文章:

python - 防止 pandas read_csv 将第一行视为列名的标题

python - 如何使用文件路径作为函数参数

html - 是否可以使用:not() selector to target specific text nodes?

javascript - 如何在 PhantomJS 中转到下一页进行抓取

python - 检查 Python 脚本是否已经在运行

python - 脚本在抓取多个值时抛出错误

python - 当 expanded_url 不够时在 Tweepy 中完成 url(与 urllib2 集成?)

python - BeautifulSoup 理解相对 URL 吗?

python - 损坏的 zip 下载 urllib2

Python yield 语句每次都返回相同的值