Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select by "name" in JSoup

I have multiple div's in a webpage URL that I have to parse which have the same class name but different names with no id's.

for eg.

<div class="answer" style="display: block;" name="yyy" oldblock="block" jQuery1317140119108="11"> 

and

<div class="answer" style="display: block;" name="xxx" oldblock="block" jQuery1317140119108="11">

I want to select data and parse from only one of the div's say namely (name="yyy") (the content inside the div's are <href> links which differ for each class.

I've looked up the selector syntax in the Jsoup webpage but can't get a way to work around it. Can you please help me with this or let me know if I'm missing something?

like image 347
Nani Avatar asked Sep 28 '11 19:09

Nani


1 Answers

Use the [attributename=attributevalue] selector.

Elements xxxDivs = document.select("div.answer[name=xxx]");
// ...

Elements yyyDivs = document.select("div.answer[name=yyy]");
// ...
like image 184
BalusC Avatar answered Oct 21 '22 17:10

BalusC