简体   繁体   English

如何使用JSOUP从div样式获取文本

[英]How to get text from div style using JSOUP

how to get the text "xxxx" and it's url using JSOUP. 如何使用JSOUP获取文本“ xxxx”及其网址。

 <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;]");

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. 由于我不了解HTML的其余部分,所以我只能猜出该区别部分是什么。 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? 但是,也许也是div的内容将其与其他内容区分开了? 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. 如果您要共享更多的HTML,我可以更具体一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM