【发布时间】:2017-12-28 14:55:15
【问题描述】:
我想用Java 解析网站中的列表。我已经知道如何使用Jsoup 解析列表 - 所以这部分已经完成并且可以工作了。
但是,要在网页中显示列表,我需要按一个按钮,但我不知道如何使用 Java 来做到这一点。我已经在 SO 上找到了类似的问题:Programmatically click a webpage button。我想我可以为此使用HttpURLConnection 和KVP,但我不知道如何让它工作。
我在 html 文件中找到的代码:
<div class="row top-buffer">
<div class="col-md-6 col-sm-4 col-xs-6 nopadding">
<button type="button" id="clearselection" class="btn btn-knx" style="float: right; margin: 0px">Clear selection</button>
</div>
<div class="col-md-6 col-sm-4 col-xs-6 nopadding">
<button type="button" id="showall" class="btn btn-knx align-right" style="float: left">Show all</button>
</div>
</div>
有人知道这是怎么做到的吗? ..顺便说一句,我需要在这个网站上按下一个按钮,否则我会手动操作。一旦我知道它是如何用一个按钮完成的,我就能为其他按钮弄清楚。
更新: 我想指出我无权访问 HTML 文件。我基本上想模拟网站访问者的按钮点击。对不起,我不清楚。
UPDATE-2:
我刚刚开始再次研究这个问题。我在网页中找到了按钮的Javascript 代码:
$('#showall').on('click', function () {
$('.mask').show();
$('#name').attr('value', '');
$("#letter option").removeAttr('selected');
$("#letter option[value='']").attr('selected', true);
$.ajax({
url: '/src/international/Data/partListAjax',
type: 'POST',
dataType: "html",
data: {
data: $('#filterForm').serialize(),
wTexts: {"Company":"Company","Country":"Country","Name":"Name","Total":"Total","search":"Search","matches_found":"matches found","search_no_results":"Your search did not match any results."},
national: 'null',
currentProject: 'nma-en'
},
success: function (data) {
if (data.indexOf("Allowed memor") >= 0) {
$('#accordion2').html("<div class='alert alert-warning' role='alert'>Please use our search engine</div>");
$('.mask').hide();
$('#clearselection').attr('disabled', 'disabled');
$('#showall').attr('disabled', 'disabled');
} else {
$('#accordion2').html(data);
$('.mask').hide();
$('#clearselection').attr('disabled', 'disabled');
$('#showall').attr('disabled', 'disabled');
}
}
});
});
如果调用按钮函数不起作用,我会尝试直接发送/触发函数中包含的Ajax 命令。
【问题讨论】:
-
您将需要某种浏览器客户端,Webview 怎么样。看到这个,stackoverflow.com/questions/30113445/…
-
删除了滥用的
android标签 -
感谢您的链接。但在这些情况下,开发人员可以访问我没有的 HTML 文件。我只有在网页源代码中找到的按钮的 ID。