【问题标题】:Using Mechanize (Python) to click on a button [duplicate]使用机械化(Python)单击按钮[重复]
【发布时间】:2013-08-28 16:15:44
【问题描述】:

我正在使用 Mechanize lib(使用 Python)来创建一个登录系统的程序。但是对于该系统,选项 Browser.Submit 不起作用。所以我试图强制我的程序点击“登录”按钮。有人知道机械化是否可以吗?

【问题讨论】:

    标签: python mechanize


    【解决方案1】:

    如果您还没有,您可以考虑查看twill。 Twill 基于 mechanize 包,有一个submit function,可以用来点击按钮。

    【讨论】:

      【解决方案2】:

      您可能还想看看ghost.py,它提供了一个可通过Python 访问的无头WebKit 浏览器(基本上是PhantomJS 的Python 变体)。单击任意按钮应该没有问题(在填写表格之后,甚至评估一些 JS 之后)。

      【讨论】:

        【解决方案3】:

        试试 RoboBrowser,它建立在 Mechanize and Beautiful Soup 之上。

        示例代码:

        from robobrowser import RoboBrowser
        crawler = RoboBrowser(history=True)
        crawler.open('http://www.whatever.com/')
        search_form = crawler.get_form(attrs={'name':'formName') #This is the name found in <formname=formName>
        search_form['keywords'] = 'search keywords' # In form[] specify the <input name=''> of the subfield within the form element that you're trying to fill in.
        crawler.submit_form(search_form)`
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-12-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-08
          • 1970-01-01
          • 1970-01-01
          • 2012-09-07
          相关资源
          最近更新 更多