如何通过python脚本在html5表单上自动填充登录值?

2024-04-26 23:25:31 发布

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

我试图制作一个脚本,自动填充HTML5表单值(名称和密码)。我不知道如何插入值。你知道吗

在其他网站上,我找不到一个很好的解释如何做到这一点。你知道吗

登录站点:https://ncod22.n-able.com/

用户名=测试名
密码=TestPwd
(这些不起作用)

Pyton代码(到目前为止):

import webbrowser, sys
webbrowser.open('https://ncod22.n-able.com/')

Tags: https脚本名称com密码表单站点网站
1条回答
网友
1楼 · 发布于 2024-04-26 23:25:31

试试mechanize

import mechanize
url="https://ncod22.n-able.com/"
pg=mechanize.Browser()
pg.set_handle_robots(False)
r=pg.open(url)   #open page
pg.select_form(nr=0)   #select form number
pg.form["username"]="TestName"   #<input> name
pg.form["password"]="TestPwd"   #<input name="password">
pg.method="POST"   #form method
r=pg.submit()   #submitting form
#print(r.read())    to see Page source

相关问题 更多 >