jsoup

Posted by Bruce Tsai
05/17/2016

在程式開發中,有不少機會會透過 HTTP client 來取得其它伺服器上的資料,這方面最知名的大概是 Apache HttpComponents,具有完整的 HTTP 封裝,但在操作上就顯得較為繁瑣。筆者目前最常用的 HTTP client 則是 jsoup,能夠滿足在一般的 HTTP GET/POST 操作需求,並且支援 HTML 文件中的 CSS selector 查詢,對於用來取得 html 內容非常方便。

使用範例

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");

results matching ""

    No results matching ""