简体   繁体   English

TD下的Jsoup和特定元素

[英]Jsoup and specific element under TD

I'm developing an app based on Jsoup Parsing. 我正在开发基于Jsoup解析的应用程序。 I love this class because it's so useful, but just now I have a problem. 我喜欢这门课,因为它很有用,但现在我有一个问题。 I can't unterstand how to select a specific element of an html page that now I'll represent by an example. 我不能理解如何选择一个html页面的特定元素,现在我将通过一个示例来表示。

<table>
<tr>

<td class=default1>
   <a href "pickthisurl.com"> text </a>
   <a><href="uselesslink.com">text </a>
</td>
<td class=default1>
   <a href "pickthisurl.com">text </a>
   <a><href="uselesslink.com">text </a>
</td>
<td class=default1>
   <a href "pickthisurl.com">text</a>
   <a><href="uselesslink.com">text</a>
</td>

<tr>
</table>

So, what I need is the url of the first under each td with that class. 因此,我需要的是该类在每个td下的第一个URL。 I'm trying with something like 我正在尝试类似的东西

Elements links = doc.select("td.default1 > a[href]"); 元素链接= doc.select(“ td.default1> a [href]”);

but this code select (and It's right) all links elements! 但是这段代码选择(并且是正确的)所有链接元素!

Try this. 尝试这个。

Elements td = doc.select("td.default1");
for(Element el : td)
{
   el.select("a[href]").first();
}

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

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