简体   繁体   English

JSoup。 我正在尝试从具有多个名称奇怪的类的跨度中获取文本,编译器不喜欢

[英]JSoup. I am trying to get text from a span that has multiple classes with strange names the compiler is not liking

Here is what I have for the code: 这是我的代码:

enter code here text = text.toUpperCase();
        Document doc = Jsoup.connect("https://finance.yahoo.com/quote/" + text + "?p=" + text).userAgent("Safari").get();

        Element temp = doc.selectFirst("span.Trsdu(0.3s).Fw(b).Fz(36px).Mb(-4px).D(ib)");

        System.out.println(temp);

Here is the span I am trying to get: 这是我想要的范围:

<span class="Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)" data-reactid="35">1,119.50</span>

I am trying to get 1119.50 but have been unable to. 我正在尝试获得1119.50,但一直无法完成。 Please help! 请帮忙! I am using netbeans as my java IDE. 我正在使用netbeans作为我的Java IDE。 I am new to JSoup so please help me if I am doing something ignorant. 我是JSoup的新手,所以如果我做不清楚的事情,请帮助我。

This code should get you the value you are looking for by selecting the first span the data-reactid you are looking for: 此代码应通过选择要查找的data-reactid的第一个跨度来为您提供所需的值:

Element test = doc.select("span[data-reactid='35']").first();
System.out.println(test.text());

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

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