Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7540667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:41:48+00:00 2026-05-30T07:41:48+00:00

So I am just trying out the Jsoup API and have a simple question.

  • 0

So I am just trying out the Jsoup API and have a simple question. I have a string and would like to keep the string in tact except when passed through my method. I want the string to pass through this method and take out the elements that wrap the links. Right now I have:

public class jsTesting {
public static void main(String[] args) {
    String html = "<p>An <a href='http://example.com/'><b>example</b></a> link and after that is a second link called <a href='http://example2.com/'><b>example2</b></a></p>";
    Elements select = Jsoup.parse(html).select("a");
    String linkHref = select.attr("href");
    System.out.println(linkHref);       
}}

This returns the first URL unwrapped only. I would like all URLs unwrapped as well as the original string. Thanks in advance

EDIT: SOLUTION:

Thanks alot for the answer and I edited it only slightly to get the results I wanted. Here is the solution in full that I am using:

public class jsTesting {
public static void main(String[] args) {
    String html = "<p>An <a href='http://example.com/'><b>example</b></a> link and after that is a second link called <a href='http://example2.com/'><b>example2</b></a></p>";
    Document doc = Jsoup.parse(html);
    Elements links = doc.select("a[href]");
    for (Element link : links) {
        doc.select("a").unwrap();
    }
    System.out.println(doc.text());
}

}

Thanks again

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:41:49+00:00Added an answer on May 30, 2026 at 7:41 am

    Here’s the corrected code:

    public class jsTesting {
        public static void main(String[] args) {
            String html = "<p>An <a href='http://example.com/'><b>example</b></a> link and after that is a second link called <a href='http://example2.com/'><b>example2</b></a></p>";
            Elements links = Jsoup.parse(html).select("a[href]"); // a with href;
            for (Element link : links) {
                //Do whatever you want here
                System.out.println("Link Attr : " + link.attr("abs:href"));
                System.out.println("Link Text : " + link.text());    
            }       
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning Erlang and am trying out some Project Euler problems
I'm just starting out writing trying to write a simple program in C and
I'm new to iPhone development and I'm just trying out some simple drawing routines
Just trying out some C on some of the project euler questions. My question
Basically, Im just trying out a very simple collision test for another program Im
So im studying and just trying something out and well, the question is this
I just recently started trying out T4MVC and I like the idea of eliminating
Just trying out ubuntu server on my pc and have been testing some commands
I have the following bit of code which I'm just trying out by running
I was just trying out Ruby and I came across String#to_i . Suppose I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.