Rectangle 27 0

jsoup html parser to search and replace the some values using java?


Is this a programming question? If you're looking for a pre-made Java file or something to do this, you're in the wrong place. If you're looking to write something like this, then you could just search for instances of text that begins with a href=/" and ends with /">, and then you could just check the href value, and if it's a relative path (that is, starts with /), you can just add the other text to the beginning.

Note
Rectangle 27 0

jsoup html parser to search and replace the some values using java?


package javaapplication4;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 *
 * @author derek
 */
public class Main
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        try
        {
            Document document = Jsoup.connect("http://www.google.com").get();
            Elements elements = document.select("a");

            for (Element element : elements)
            {
                element.baseUri();
            }
            System.out.println(document);
        }
        catch (Exception e)
        {
            e.printStackTrace(System.err);
        }
    }
}
Note
Rectangle 27 0

jsoup html parser to search and replace the some values using java?


private void absoluteLinks(Document document, String baseUri)    {
    Elements links = document.select("a[href]");
    for (Element link : links)  {
        if (!link.attr("href").toLowerCase().startsWith("http://"))    {
            link.attr("href", baseUri+link.attr("href"));
        }
    }
}

this code change relative links in document to absolute links the code use jsoup library

Note
Rectangle 27 0

jsoup html parser to search and replace the some values using java?


<a href="/
html = html.replaceAll("<a href=\"/", "<a href=\"http://www.google.com/\"");

You could do this with String.replaceAll() and a regexp that matched on

Note