简体   繁体   中英

Java - Jsoup How would I extract the title and link in this HTML code?

I would like to extract the title "Syrian arch razed by ISIS and re-created with 3D " in this HTML code, along with its link "http://www.theverge.com/2016/9/19/12972504/palmyra-arch-of-triumph-isis-3d-replica-new-york-city" from the google news site: https://www.google.com/search?hl=en&gl=us&tbm=nws&authuser=0&q=technology

I would really appreciate your help, thanks,

Sorry I have to have an image but StackOverflow was formatting the code weirdly

HTML Code

I suggest you visit this link and experiment with this

        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();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM