【问题标题】:Getting 'FormNotFoundError' in mechanize Python在机械化 Python 中获取“FormNotFoundError”
【发布时间】:2017-12-12 14:37:20
【问题描述】:

我正在使用漂亮的汤和机械设备来抓取银行网站。

import re
import mechanize


br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_equiv(False)
response = br.open("https://m.netbanking.hdfcbank.com/netbanking/")


br.select_form(nr=0)
br.form['fldLoginUserId'] = "131325"
br.submit()

我需要在客户 ID 文本框中输入值,但每次都出现异常。谁能帮帮我。

Traceback (most recent call last):
  File ".\main.py", line 12, in <module>
    br.select_form(nr=0)
  File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 669, in select_form
    raise FormNotFoundError("no form matching " + description)
mechanize._mechanize.FormNotFoundError: no form matching nr 0

【问题讨论】:

  • 仔细阅读错误信息。它对你说了什么?
  • 那个页面上有表格,如果我们看一下HTML页面,我们可以观察到。我尝试了我的方法,但我找不到任何解决方案。即使它没有显示该页面中的任何可用表单。

标签: python python-2.7 mechanize


【解决方案1】:

尝试使用 selenium 来完成这项任务。

from selenium import webdriver

driver = webdriver.Firefox(executable_path='./drivers/geckodriver')

driver.get('https://m.netbanking.hdfcbank.com/netbanking/')

driver.find_element_by_xpath('//*[@id="fldLoginUserId"]').click()

driver.find_element_by_xpath('//*[@id="fldLoginUserId"]').send_keys('131325')


driver.find_element_by_xpath('//*[@id="logintable"]//input[@type="submit"]').click()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多