我正在尝试弄清楚如何使用 Jsoup 提交表单。 在 Xfinity 的网站上,我尝试输入一个地址,并在点击以下网址中的“显示我的优惠”后返回结果页面:
https://www.xfinity.com/learn/offers
这是我当前的代码:
public String getISP() throws IOException {
Connection.Response addressFormResponse = Jsoup.connect("https://www.xfinity.com/learn/offers")
.data("Address.SingleStreetAddress", address)
.method(Connection.Method.POST)
.execute();
Document doc = addressFormResponse.parse();
System.out.println(doc.title());
System.out.println(doc.location());
if (doc.location().contains("Active Address")) {
return "Comcast XFinity";
}
return "Cannot find an ISP";
}
当前代码仅返回相同的网页,我如何取回结果页面?
最佳答案
Jsoup 是一个 HTML 解析器库,它提供了提取和操作 HTML 页面上的数据的功能。如果你需要遍历网站、提交表单、点击元素,最好使用其他工具,比如selenium , HTTP client (通常用于网络应用程序的自动化测试)或网络爬虫库,如 crawler4j .
关于Java Jsoup 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60290961/