Extraiga enlaces del documento jsoup que contengan alguna cadena a otra cadena

yo suelo jsopa to extract the links from a website. i want to extract one only specified link containg some keywords. i want to retrieve the links contains the keyword "download". how to do it. i have the following code

Document doc = Jsoup.parse( new URL("http://www.examplesite.com)); 
Element link = doc.select("a").first();

preguntado el 09 de marzo de 12 a las 15:03

2 Respuestas

Vea aquí for the selector syntax.

You can test for the text within a node with :contains, p.ej Element link = doc.select("a:contains(Download)").first();. If you want you can use :matches for regex.

You get the link address via the attr método, por ejemplo String linkaddress = link.attr("href");.

respondido 09 mar '12, 15:03

also i would like to convert to string.? - Jessy Jameson

in the doc i get to matches(jsoup finds 2 links, the same links), is it possible to get only the first one and convert to a string? thank you - Jessy Jameson

puedes usar esto

elements with attributes that start with [attr^=value],end with [attr$=value],contain the value [attr*=value] e.g. [href*=/path/]

you want to get the links containing certain word use this

org.jsoup.select.Elements links = doc.select("[href*=download]");

Respondido el 19 de enero de 17 a las 18:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.