Java - Jsoup如何在此HTML代码中提取标题和链接?

时间:2016-09-19 23:36:40

标签: java jsoup

我想从Google新闻网站中提取此HTML代码中的标题"Syrian arch razed by ISIS and re-created with 3D "及其链接"http://www.theverge.com/2016/9/19/12972504/palmyra-arch-of-triumph-isis-3d-replica-new-york-city"https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin

我非常感谢你的帮助,谢谢,

抱歉,我必须有一张图片,但StackOverflow正在格式化代码

https://www.google.com/search?hl=en&gl=us&tbm=nws&authuser=0&q=technology

1 个答案:

答案 0 :(得分:0)

我建议您访问此link并尝试使用此

        try {
            // Connect to the web site
            Document document = Jsoup.connect(url).get();
            // Get the html document title
            title = document.title();
            Element link = document.select("a.l _HId");
            String s1 = link.absUrl("src"); //Gives you link
            String s2 = link.text(); //Gives you Required text
        } catch (IOException e) {
            e.printStackTrace();
        }