我正在尝试提取这段 html 代码的值:
<ul id="tree-dotlrn_class_instance">
<li>
<a href="/dotlrn/classes/c033/13000/c12c033a13000gA/">**2011-12 Ampl.Arquit.Computadors Gr.A (13000)**</a>
<ul>
<li>
<a href="/dotlrn/classes/c033/13022/c12c033a13022gA/c12c033a13022gAsT00/">**2011-12 Entorns d'Usuari Gr.A Sgr.T00 (13022)** </a>
</li>
<li>
<a href="/dotlrn/classes/c033/13036/c12c033a13036gA/c12c033a13036gAsT00/">**2011-12 Eng.Serv.Telemàtics Gr.A Sgr.T00 (13036)** </a>
</li>
</ul>
</li>
<li>
<a href="/dotlrn/classes/c033/13038/c12c033a13038gA/">**2011-12 Intel·lig.Artif.Enginyer.Coneixem. Gr.A (13038)**</a>
</li>
<li>
<a href="/dotlrn/classes/c033/13048/c12c033a13048gA/">**2011-12 Processad.Llenguatge Gr.A (13048)**</a>
<ul>
<li>
<a href="/dotlrn/classes/c033/13048/c12c033a13048gA/c12c033a13048gAsL01/">**2011-12 Processad.Llenguatge Gr.A Sgr.L01 (13048)** </a>
</li>
<li>
<a href="/dotlrn/classes/c033/13048/c12c033a13048gA/c12c033a13048gAsT00/">**2011-12 Processad.Llenguatge Gr.A Sgr.T00 (13048)** </a>
</li>
<li>
<a href="/dotlrn/classes/c033/13052/c12c033a13052gA/c12c033a13052gAsL02/">**2011-12 Sist.Basats Microprocessadors Gr.A Sgr.L02 (13052)** </a>
</li>
</ul>
</li>
<li>
<a href="/dotlrn/classes/c033/13055/c12c033a13055gAA/">**2011-12 Sist.Informàtics Gr.AA (13055)**</a>
</li>
<li>
<a href="/dotlrn/classes/c033/14009/c12c033a14009gA/">**2011-12 Administrac. Gestió de Xarxes Gr.A (14009)**</a>
</li>
<li>
<a href="/dotlrn/classes/c033/15656/c12c033a15656gA/">**2011-12 Transmissió de Dades Gr.A** (15656)</a>
</li>
</ul>
所有这一切都是在强烈的黑色(**之间)与他的href值进入一个HashMap。首先我尝试使用 jericho html 解析器,但我认为它很复杂,然后我尝试使用 Regex,但我不知道该怎么做。你能帮助我吗 ??
谢谢!
更新:我正在尝试这个,但这不是正确的方法。
Source s = new Source(answer);
List<Element> Form1 = s.getAllElements(HTMLElementName.UL);
int tam1 = Form1.size();
for(int j = 0; j < tam1; j++){
Element e1 = Form1.get(j);
if("tree-dotlrn_class_instance".equals(e1.getAttributeValue("id"))){
List<Element> L1 = e1.getAllElements(HTMLElementName.UL);
for (int k = 0; k < L1.size(); k++){
Element e2 = L1.get(k);
System.out.println("Elemento de la lista L1: "+e2.getContent());
List<Element> L2 = e2.getAllElements(HTMLElementName.LI);
for(int m = 0; m < L2.size(); m++){
Element e3 = L2.get(m);
System.out.println("Elemento de la lista L2: "+e3.getContent());
asignaturas.add(e3.getContent().toString());
System.out.println("Lista de asignaturas "+m+" "+asignaturas.get(0));
}
}
}
}