我正在尝试使用JSOUP从网页获取SELECT节点。我遇到的问题是,我只是在SELECT节点内获得了第一个OPTION节点。当我检查上述网页的html源代码时,我发现SELECT节点内有9个OPTION节点。这是我正在使用的Java代码:

Document doc;
Elements stops;
try {
  doc = Jsoup
    .connect("http://www.miamidade.gov/transit/mobile/scriptCheck.asp?
         script=yes&CurrentPage=/transit/mobile/schedules.asp?route=3")
    .userAgent(" Mozilla/5.0")
    .timeout(30000)
    .get();

stops = doc.getElementsByTag("select");

for (Element option : stops) {
    System.out.print(option.text());
}

} catch (IOException e) {
    e.printStackTrace();
}

最佳答案

如果您只是直接转到提到的网页,则确实会获得带有单个选项(“-”)的select元素。为了获得所有选项,您需要返回http://www.miamidade.gov/transit/mobile/routes.asp?route=3并单击“查看计划”。我猜想为了使它起作用,您首先必须发送该POST请求,以使select选项具有所有选项。

09-10 03:19
查看更多