使用JSoup。它是一个 HTML 解析器,允许您使用 css 选择器(如 jQuery)访问 DOM 元素。
// Parse your HTML:
// 1. From string:
Document doc = JSoup.parse(htmlAsString);
// 2. Or from an URL:
Document doc = JSoup.connect("http://my.awesome.site.com/").get();
// Then select images inside it:
Elements images = doc.select("img");
// Then iterate
for (Element el : images) {
String imageUrl = el.attr("src");
// TODO: Do something with the URL
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7756 次 |
| 最近记录: |