84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
<p class="info-detail-head-classify-subname"><a id="info_detail_head_classify_type" href="" target="_blank">财富</a></p> 想用java 提取财富两个字 请问用正则怎么提取 用jsoup会不会简单一点
You can use jsoup and regex, it is recommended to use jsoup!jsoup document:https://jsoup.org/cookbook/in...http://www.open-open.com/jsoup/
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { // 方法1: jsoup String html = "<p class=\"info-detail-head-classify-subname\"><a id=\"info_detail_head_classify_type\" href=\"\" target=\"_blank\">财富</a></p>"; Document doc = Jsoup.parse(html); Element element = doc.getElementById("info_detail_head_classify_type"); System.out.println(element.text()); // 方法2: regex Pattern r = Pattern.compile("<a.*>(.*)</a>"); Matcher m = r.matcher(html); if (m.find()) { System.out.println(m.group(1)); } } }
<a[^>]*>([^<]*)</a>
Get the content in <a></a>
<a></a>
You can use jsoup and regex, it is recommended to use jsoup!
jsoup document:
https://jsoup.org/cookbook/in...
http://www.open-open.com/jsoup/
Get the content in
<a></a>