0

I have some troubles into slitting an Element (scraped from the web) into an Array of Strings.

Here is my code :

link = "http://www.myurl.com"
val doc: Document = Jsoup.connect(link).get()
val title2 = doc.select("li > h3 > a").toString

that give me :

<a href="/association/129033/69-1ere-compagnie-d-arc-du-dauphine.htm">1ERE COMPAGNIE D'ARC DU DAUPHINÉ</a>
<a href="/association/129512/69-38sms.htm">38SMS</a>
<a href="/association/128940/69-40-batteurs.htm">40 BATTEURS</a>
<a href="/association/129543/69-4l-four-liberty.htm">4L FOUR LIBERTY</a>
<a href="/association/129820/69-a-bord-perdu.htm">A BORD PERDU</a>

what i want is to have only the href in a Array of Strings. Only take the strings in the " ".

I've try to use JavaConverters like asScala, but i'm falling working with it :/

Thanks

1 Answer 1

1

simply extract href attributes from the a you get like:

doc.select("li > h3 > a").map(link -> link.attr("href")).toArray

take a look the more attribute extracting features from Jsoup

Sign up to request clarification or add additional context in comments.

2 Comments

did you mean : doc.select("li > h3 > a").map(doc -> doc.attr("href")).toArray ? also map make an error (map not a member of org.jsoup.Elements)
i do not have how to test it but try this -> doc.select("li > h3 > a").asScala.map(doc -> doc.attr("href")).toArray . Let me know it it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.