android向webview加载的页面中填充账号密码并且自动登陆遇到问题求解

在尝试使用Android WebView加载网页并自动填充账号密码实现自动登录时遇到了问题。代码中通过Jsoup连接网页并替换字符串以注入js脚本,但登录按钮变得无法点击。目前js代码为`fillAccount`函数,目标是将账号和密码自动填入网页输入框。寻求解决方案,特别是关于js注入的正确方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


 public static String LOGIN = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=46000101&style=8&lang=&low_login=1&hide_title_bar=1&hide_close_icon=1&daid=6&hln_css=http://mat1.gtimg.com/www/mb/images/logo244x100.png&s_url=https%3A%2F%2F2.zoppoz.workers.dev%3A443%2Fhttp%2Fw.t.qq.com%2Ftouch";

final String tencent_url = LOGIN;
try {

            String js = FileUtils.readAssetsFile("oauthfortencent.js", TencentWeiboActivity.this);

            js = js.replace("%u%", tAccount).replace("%p%", tPassword);

            Document dom = Jsoup.connect(LOGIN).get();
            html = dom.toString();
            html = html.replace("</head>", js + "</head>")
                    .replace("action-type=\"submit\"", "action-type=\"submit\" id=\"submit\"");
            return html;
        } catch (Exception e) {
            e.printStackTrace();
        }
                mWebView.loadDataWithBaseURL("http://open.qq.com/", html, "text/html", "UTF-8", "");

js代码

function fillAccount(){ document.getElementById("u").value = '%u%'; document.getElementById("p").value = '%p%'; document.getElementById("go").click(); }

原本的网页是这样子的
被我加了js之后变成这样子:
登录按钮也不能被点击,
我应该怎么弄才可以,求助,谢谢。
js注入应该怎么注入,不是代码中那样子的么
求助,如果解释的话,可以详细一点么,谢谢
我想要实现的效果就是把账号和密码自动填入网页中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值