久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

java - 如何用正則提取html內(nèi)容

瀏覽:130日期:2023-12-04 08:35:21

問題描述

<p class='info-detail-head-classify-subname'><a href='http://www.baoyu77737.com/wenda/11492.html' target='_blank'>財(cái)富</a></p> 想用java 提取財(cái)富兩個(gè)字 請(qǐng)問用正則怎么提取 用jsoup會(huì)不會(huì)簡(jiǎn)單一點(diǎn)

問題解答

回答1:

可以使用jsoup和regex, 推薦使用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 href='http://www.baoyu77737.com/wenda/11492.html' target='_blank'>財(cái)富</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)); }} }回答2:

<a[^>]*>([^<]*)</a>

取<a></a>中的內(nèi)容

標(biāo)簽: HTML
相關(guān)文章:
主站蜘蛛池模板: 宁明县| 贡山| 珲春市| 灵台县| 襄汾县| 西畴县| 宁明县| 抚松县| 武清区| 都兰县| 贞丰县| 灵璧县| 罗城| 来凤县| 瑞昌市| 黄石市| 久治县| 九寨沟县| 金阳县| 海口市| 阿拉尔市| 芷江| 鹤庆县| 昌江| 桐柏县| 苗栗市| 喀什市| 南和县| 峨边| 拉萨市| 横山县| 贡嘎县| 天全县| 关岭| 茶陵县| 盘山县| 五家渠市| 永清县| 分宜县| 喀喇沁旗| 德化县|