版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_33704704/article/details/72458683
jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址、HTML文本内容。它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据。
进入http://www.open-open.com/jsoup/下载jsoup
通过链接获取到http://www.toutiao.com/i6418888898197324289/里的图片地址demo:
public static void main(String[] args) {
Document doc = null;
try {
doc = Jsoup.connect("http://www.toutiao.com/i6418888898197324289/").get();
String title = doc.title();
System.out.println(title);
Element getnr = doc.body();
Elements getDiv = getnr.getElementsByTag("img");
for (Element element : getDiv) {
String src = element.attr("src");
System.out.println(" ** "+src);
}
} catch (IOException e) {
e.printStackTrace();
}
}
结果:经典猫咪动图,个个都是表情帝 - 今日头条(www.toutiao.com)
** //s3.pstatp.com/toutiao/resource/ntoutiao_web/static/image/logo_201f80d.png
** http://p9.pstatp.com/large/1f8b0002684bedc0ceb9
** http://p3.pstatp.com/large/1f81000656ee902713af
** http://p3.pstatp.com/large/1f8100065696f9a342d5
** http://p3.pstatp.com/large/1f8b0002687648102308
** http://p3.pstatp.com/large/1f8a00029e896c2b9876
** http://p3.pstatp.com/large/1f86000655dc71a37e32
** http://p1.pstatp.com/large/1f83000657b96448ad81