我試圖從網站獲取數據。使用此代碼:如何使用Jsoup從網站獲取內容
@WebServlet(description = "get content from teamforge", urlPatterns = { "/JsoupEx" })
public class JsoupEx extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String URL = "http://www.moving.com/real-estate/city-profile/results.asp?Zip=60505";
public JsoupEx() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Document doc = Jsoup.connect(URL).get();
for (Element table : doc.select("table.DataTbl")) {
for (Element row : table.select("tr")) {
Elements tds = row.select("td");
if (tds.size() > 1) {
System.out.println(tds.get(0).text() + ":"
+ tds.get(2).text());
}
}
}
}
}
我正在使用jsoup解析器。運行時,我不會有任何錯誤,只是沒有輸出。
請幫忙。
猜猜別人會需要更多的洞察力!如果您沒有收到任何錯誤,請提供信息,比如您如何嘗試運行該程序。 – LGAP 2013-02-15 09:10:01
您的程序中的網址不起作用。該頁面不包含表格。 – CharliePrynn 2013-02-15 09:10:53
你確定你的servlet正在部署成功嗎?檢查您的服務器日誌是否有錯誤,並在發現問題時將其包含在您的問題中 – Perception 2013-02-15 09:11:16