WhiteBanana
WhiteBanana

Reputation: 349

How to get text from div style using JSOUP

how to get the text "xxxx" and it's url using JSOUP.

<div style="width:45%;float:left;border: dashed 1px #966;margin:0 10px;padding:10px;height:400px;">
    <ul>		
        <li><a href="http://xxx.xxx.com/Title?xxxxx" target="_blank">xxxx</a></li>
        <li><b>years:</b>2015</li>
        <li><b>language:</b>non </li>
        <li><b>color:</b>color</li>
    </ul>
</div>

This is my current approach but I receive nothing:

Elements mvYearElement = doc.select("div[style*=width:45%;float:left;border: dashed.1px #966;margin:0 10px;padding:10px;height:400px;]");

Upvotes: 1

Views: 1209

Answers (1)

luksch
luksch

Reputation: 11712

The problem is probably that styles do not need to appear in an particular order. Your selector however fixates the order and lists a lot of styles. I would try to identify the part of the style the really is discriminating the link and only use this part. Since I don't know the rest of the HTML i only could guess what is that discriminating part. This maybe?

Elements els = doc.select(div[style*=dashed]);

That is only a wild guess however. But maybe it is also the contents of the div that are discriminating it from the others? In that case you could do something like this:

Elements els = doc.select(div[style]:has(ul));

Or something else. If you would share more of the HTML I could be more specific.

Upvotes: 2

Related Questions