0
我需要編譯一個模式,以獲得跨度的名稱,但徒勞無功我不能擁有我想要的可能是這種模式寫入的方式我知道我做了一些不完全正確的事情..這是我的html代碼:我如何提取使用java的跨度名稱?
<span class="libelleAttributPageParametrage">
"Libellé de facturation"
<font color="#C60307">*</font>
</span>
,這是我的Java代碼:
public List<String> getAllSpan()
{
String HTMLSource = priceSelenium.getHtmlSource();
priceSelenium.getBodyText();
List<String> ListOfSpan = new ArrayList<String>();
Pattern p = Pattern.compile("<SPAN[^>]*>([\\w\\d\\s\\n\\r()/°@\\.\\-àáâãäåçèéêëìíîïðòóôõöùúûüýÿ]*)</SPAN>");
Matcher m = p.matcher(HTMLSource);
while (m.find())
{
if (!m.group(1).isEmpty())
{
ListOfSpan.add(m.group(1));
}
}
return ListOfSpan;
}
,什麼我需要在我的ListOfSpan是: 「Libellé德facturation」 提前
感謝
請不要使用RegEx解析HTML,因爲它會[驅動你į̷̷͚̤̤̖̦͍͗̒̈̅̄n̨͖͓̹͍͎͔͈̝͐ͪ͛̄͛ṣ̷̵̞̦ͤ̅̉̋ͪ͑͛ͥ͜a̷̘͖̮͔͎͛̇̏̒͆̆͘n͇͔̤̼͙̩͖̭ͤ͋̉͌͟eͥ͒ͥ͒](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)。改爲使用HTML解析器 – HashimR 2012-08-02 08:31:44