【发布时间】:2013-08-28 16:15:44
【问题描述】:
我正在使用 Mechanize lib(使用 Python)来创建一个登录系统的程序。但是对于该系统,选项 Browser.Submit 不起作用。所以我试图强制我的程序点击“登录”按钮。有人知道机械化是否可以吗?
【问题讨论】:
我正在使用 Mechanize lib(使用 Python)来创建一个登录系统的程序。但是对于该系统,选项 Browser.Submit 不起作用。所以我试图强制我的程序点击“登录”按钮。有人知道机械化是否可以吗?
【问题讨论】:
如果您还没有,您可以考虑查看twill。 Twill 基于 mechanize 包,有一个submit function,可以用来点击按钮。
【讨论】:
试试 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)`
【讨论】: