简体   繁体   中英

Get an URL hidden in HTML code with JSoup

I have a piece of HTML code of a web page (library thing) like:

    <div class="qelcontent" id="4ed0e0ba4f1b16.47984984" style="display:block;"> 
<div class="description"><h4 class="first"><b>Amazon.com Product Description</b>
(<a href="https://rads.stackoverflow.com/amzn/click/com/0860783227" rel="nofollow noreferrer">ISBN 0860783227</a>, Hardcover)</h4>

I want to get the absolute URL from an href attribute. I tried:

selector = document.select(".first .a[href]");

But it returned null . How can I get the value?

This solves this specific problem.. not sure if it will work with your entire dataset.

    String html = "<div class=\"qelcontent\" id=\"4ed0e0ba4f1b16.47984984\" style=\"display:block;\">" + 
    "<div class=\"description\"><h4 class=\"first\"><b>Amazon.com Product Description</b>" +
    "(<a href=\"http://rads.stackoverflow.com/amzn/click/0860783227\">ISBN 0860783227</a>, Hardcover)</h4>";

    Document doc = Jsoup.parse(html);
    System.out.println(doc.select(".first").select("a").attr("href"));

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