简体   繁体   English

jsoup 没有从网页中获取一些 html 标签

[英]jsoup is not getting some html tags from a webpage

I am trying to get a SELECT node from a webpage using JSOUP.我正在尝试使用 JSOUP 从网页中获取 SELECT 节点。 The problem that I have is that I just get the first OPTION node inside the SELECT node.我遇到的问题是我只是在 SELECT 节点中获得了第一个 OPTION 节点。 When I checked the html source code for the above-mentioned webpage, I see that there are 9 OPTION nodes inside the SELECT node.当我查看上述网页的 html 源代码时,我看到 SELECT 节点内部有 9 个 OPTION 节点。 This is the java code I am using:这是我正在使用的 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();
}

If you just go directly to the webpage noted, you do get a select element with a single option ("-").如果您只是 go 直接访问所注明的网页,您会得到一个带有单个选项(“-”)的 select 元素。 In order to get all of the options, you need to go back to http://www.miamidade.gov/transit/mobile/routes.asp?route=3 and click "View Schedule".为了获得所有选项,您需要将 go 返回到http://www.miamidade.gov/transit/mobile/routes.asp?route=3并单击“查看时间表”。 I'm guessing that in order to get this to work, you will first have to send that POST request in order to get the select will all of the options.我猜为了让它工作,你首先必须发送那个 POST 请求才能获得 select 将所有的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM