找不到带有mechaniz的窗体

2024-06-26 14:36:02 发布

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

如果您查看下面链接的源代码,您将看到两个表单,我希望选择一个名为“doLoginPin”的表单。当我做下面的表格是找不到的。此表单是动态生成的,因此找不到它吗?以前有没有人遇到过这种情况并想出了解决办法?在

br.open('https://www.getipass.com/ipass/LoginPin.jsp')

for f in br.forms():
    print f

最终我的目标是登录并获取一些基本的账户数据。谢谢您。在


Tags: httpsbrcom表单源代码链接www情况
1条回答
网友
1楼 · 发布于 2024-06-26 14:36:02

一个简单的方法是使用Selenium Webdriver。它允许你驱动一个真正的浏览器发出请求。它有时可能有点重,但我发现它对这些小任务很有用(我建议使用Firefox作为驱动的浏览器)。在

您可以使用pip install selenium安装它。在

此脚本将尝试使用用户名foo和密码bar登录。在

from selenium import webdriver

if __name__ == '__main__':
    url = 'https://www.getipass.com/ipass/LoginPin.jsp'
    driver = webdriver.Firefox()
    driver.get(url)

    username = driver.find_element_by_name('txtLoginParam')
    password = driver.find_element_by_name('txtPass')
    username.send_keys('foo')
    password.send_keys('bar')
    password.submit()

相关问题 更多 >