Java JSoup选择问题

Java JSoup选择问题,java,html,jsoup,Java,Html,Jsoup,在html中选择链接时遇到问题。以下是我的html: <div class=first> <a href=www.test1.com>test1</a> <div class=nope> <a href=www.test2.com>test2</a> <a href=www.test3.com>test3</a> <a href=

在html中选择链接时遇到问题。以下是我的html:

<div class=first>
    <a href=www.test1.com>test1</a>

    <div class=nope>
        <a href=www.test2.com>test2</a>
        <a href=www.test3.com>test3</a>
        <a href=www.test4.com>test4</a>
    </div>
</div>

我要做的是拉取URL:
www.test2.com
www.test3.com
www.test4.com

我试过很多不同的。选择和。不是组合,但我就是想不出来。有人能指出我做错了什么吗

String url = "<div class=first><a href=www.test1.com>test1</a>One<div class=nope><a href=www.test2.com>test2</a>Two</div></div><div class=second><a href=www.test3.com>test3</a></div>";
Document doc = Jsoup.parse(url);
Elements divs = doc.select("div a[href]").not(".first.nope a[href]"); 
System.out.println(divs);
String url=“OneTwo”;
Document doc=Jsoup.parse(url);
Elements divs=doc.select(“div a[href]”)。而不是(“.first.nope a[href]”);
系统输出打印LN(divs);

我会做一些不同的事情:

  Elements elements = doc.select("div.nope").select("a[href]");

  for (Element element : elements) {
     System.out.println(element.attr("href"));
  }

你能发布你的代码片段吗?我在这里用这个片段测试它
stringurl=“OneTwo”;Document doc=Jsoup.parse(url);Elements divs=doc.select(“div a[href]”)。而不是(“.first.nope a[href]”);系统输出打印LN(divs)
@Peck3277:请不要在评论中发布代码,因为正如您所看到的,代码是不可能读取的。最好先编辑您的原始帖子,然后发布一条评论,说明您已经发布了一条编辑信息。@HovercraftFullOfEels很抱歉,可以!拆下.first();在第二行中,因为它只返回一个元素。
  Elements elements = doc.select("div.nope").select("a[href]");

  for (Element element : elements) {
     System.out.println(element.attr("href"));
  }
Elements data=doc.getElementsByClass("nope")

for(Element d:data)
{
    String yourData= d.tagName("href").toString();
}