XPath-Knoten kommen nach der neuen Zeile

Ich versuche, den Knotentext für die Knoten zu erhalten, die div align center haben: `

                <tr> 
                  <td width="39" class="back1"><b class="texto4">CRN</b></td>
                  <td width="60" class="back1"><b class="texto4">Materia</b></td>
                  <td width="53" class="back1"><b class="texto4">Secci&oacute;n</b></td>
                  <td width="55" class="back1"><b class="texto4">Cr&eacute;ditos</b></td>
                  <td width="156" class="back1"><b class="texto4">T&iacute;tulo</b></td>
                  <td width="69" class="back1"><b class="texto4">Cupo</b></td>
                  <td width="57" class="back1"><b class="texto4">Inscritos</b></td>
                  <td width="77" class="back1"><b class="texto4">Disponible</b></td>
                </tr>
                <tr> 
                  <td width="39"><font class="texto4"> 
                    10110                        </font></td>
                  <td width="60"><font class="texto4"> 
                    IIND1000                        </font></td>
                  <td width="53"><font class="texto4"> 
                  <div align="center">
                    1                        </div></font></td>
                  <td width="55"><font class="texto4"> 
                    <div align="center">
                    3                       </div>
                    </font></td>
                  <td width="156"><font class="texto4"> 
                    INTROD. INGEN. INDUSTRIAL                        </font></td>
                  <td width="69"><font class="texto4"> 
                    100                        </font></td>
                  <td width="57"><font class="texto4"> 
                    100                        </font></td>
                  <td width="77"><font class="texto4"> 
                    0                        </font></td>
                </tr>
              </table> `

Das Problem ist, dass JTidy den Text in diesem untergeordneten Knoten nicht abruft, weil (ich gehe hier davon aus) eine neue Zeile dazwischen liegt<font class="texto4"> und<div align="center">. Die Ausgabe, wenn ich jedes Element unter diesem Knoten in einer Liste erhalte und es drucke, ist leer.

Meine XPathExpression ist bisherexpr = xpath.compile("//td[@width='55']/font/div/text()"); (oder width = '69 'für den anderen Knoten).

Mein vollständiger Codeversuch ist:

String cod = "IIND2401";
    String dep = cod.substring(0, 4);
    System.out.println(dep);
    try {
        URL url = new URL("http://registroapps.uniandes.edu.co/scripts/adm_con_horario1_joomla.php?depto="+dep);
        Tidy tidy = new Tidy();
        tidy.setXHTML(true);    
        Document doc = tidy.parseDOM(url.openStream(), System.out);

        // Use XPath to obtain whatever you want from the (X)HTML
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression expr = xpath.compile("//td[@width='39']/font/text()");
        NodeList crn = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);

Dann nehme ich die erhaltenen Codes, füge sie in eine Liste ein und drucke sie aus:

List<String> crns = new ArrayList<String>();
        for (int i = 0; i < crn.getLength(); i++) {
            crns.add(crn.item(i).getNodeValue()); 
        }

System.out.println ("CRNs:"); System.out.println (crns);

Das Ergebnis ist eine lange Liste von IDs für Kurse an meiner Universität für die IIND-Fakultät. CRNs: [10110, 16886, 12420, 12526, 12527, 12528, 13510, 15146, 12544, 12545, (...)] Ich kann das HTML-Dokument nicht ändern. Ich versuche, dies von der Website meiner Universität zu analysieren . Irgendein Rat? Danke Leute.

Antworten auf die Frage(0)

Ihre Antwort auf die Frage