user3187131
user3187131

Reputation: 273

Copy selected text from the Website Java

I want to copy the text that's in Red from the following website. I don't want any HTML Code as I could get that but I am looking for a way to simply copy all the text that's in Red. I know I could do that manually but that's not something that I am looking for. I would really appreciate for sharing any code.

http://www.srigranth.org/servlet/gurbani.gurbani?Action=Page&Param=1&g=1&h=0&r=0&t=0&p=0&k=0&fb=0

Upvotes: 0

Views: 1122

Answers (1)

fvu
fvu

Reputation: 32953

JSoup allows you to read a web page and iterate over its content elements.

Sting yourURL = "servlet/gurbani.gurbani?Action=Page&Param=1&g=1&h=0&r=0&t=0&p=0&k=0&fb=0";
Document doc = Jsoup.connect(yourURL).get();

I don't understand what's on that page, but it looks like the text you're after might be the inner html of a links with class dict. If that's the case,

Elements links = doc.select("a.dict");

will give you an iterable collection of Element of which you can easily extract the text content:

for (Element word : links) {
    String theTextyoureafter = word.html();
}

That's the basic idea, you'll probably need to experiment a bit to get it "just right", but there are also a lot of examples on the Jsoup website.

Upvotes: 3

Related Questions