使用Mechanize(Python)单击按钮

2024-10-02 02:28:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用mechanizelib(使用Python)来创建一个程序来登录系统。但对于那个系统浏览器。提交不起作用。所以我试图强迫我的程序点击“登录”按钮。有人知道机械化是否可能吗?在


Tags: 程序系统浏览器按钮机械化mechanizelib
3条回答

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

试试RoboBrowser,它是建立在机械化和美丽的汤之上。在

示例代码:

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)`

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

相关问题 更多 >

    热门问题