Java Jsoup使用部分类名在span中获取类

Java Jsoup使用部分类名在span中获取类,java,jsoup,Java,Jsoup,我有一个网站,有一个不同的“pid”在一个类的每个页面,我需要去 下面是网站的HTML。“348”是什么变化: <span class="arial_20 redFont pid-348-pc" dir="ltr">-5.60</span> 我想知道如何在搜索时省去pid号。您可以使用CSS选择器指定部分类名 例如: String html = "<html>" + "<span class=\"arial_20 redFont

我有一个网站,有一个不同的“pid”在一个类的每个页面,我需要去

下面是网站的HTML。“348”是什么变化:

 <span class="arial_20 redFont   pid-348-pc" dir="ltr">-5.60</span>

我想知道如何在搜索时省去pid号。

您可以使用CSS选择器指定部分类名

例如:

String html = "<html>" +
        "<span class=\"arial_20 redFont   pid-348-pc\" dir=\"ltr\">-5.60</span>" +
        "<span class=\"arial_20 redFont \" dir=\"ltr\">55.80</span>" +
        "</html>";

Document doc = Jsoup.parse(html);

// this will print out -5.60 since the only span with a class matching 'arial_20 redFont   pid-*'
// is the one with the value: -5.60
// the other span does not match that CSS selector
String sPriceChange = doc.select("span[class*=\"arial_20 redFont   pid-\"]").text();
System.out.println("Price Change = " + sPriceChange + "\n");
String html=“”+
"-5.60" +
"55.80" +
"";
Document doc=Jsoup.parse(html);
//这将打印出-5.60,因为唯一的跨度与“arial_20 redFont pid-*”匹配
//是值为:-5.60的
//另一个跨度与该CSS选择器不匹配
字符串sPriceChange=doc.select(“span[class*=\”arial\u 20 redFont pid-\”])。text();
System.out.println(“价格变化=“+sPriceChange+”\n”);

请提供您所需的URL供参考或完整的HTML源代码部分。谢谢!!我是JSoup的新手,我想知道这个类是如何工作的!!
String html = "<html>" +
        "<span class=\"arial_20 redFont   pid-348-pc\" dir=\"ltr\">-5.60</span>" +
        "<span class=\"arial_20 redFont \" dir=\"ltr\">55.80</span>" +
        "</html>";

Document doc = Jsoup.parse(html);

// this will print out -5.60 since the only span with a class matching 'arial_20 redFont   pid-*'
// is the one with the value: -5.60
// the other span does not match that CSS selector
String sPriceChange = doc.select("span[class*=\"arial_20 redFont   pid-\"]").text();
System.out.println("Price Change = " + sPriceChange + "\n");