2011-08-11 40 views
0

我想从使用JSOUP的网页获取SELECT节点。我有的问题是,我只是在SELECT节点中获得第一个OPTION节点。当我检查上述网页的html源代码时,我发现SELECT节点中有9个OPTION节点。这是我使用的Java代码:jsoup没有从网页获取一些html标签

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(); 
} 

回答

1

如果你只是直接转到该网页所指出的,你得到一个单选项(“ - ”)select元素。为了获得所有选项,您需要返回http://www.miamidade.gov/transit/mobile/routes.asp?route=3并单击“查看时间表”。我猜测为了让这个工作起作用,你首先必须发送POST请求,以便选择所有的选项。