Python中文网

一个关于 编程问题的解答网站.

有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java XPath表达式,以在其他元素之后获取元素

我有以下结构:

<html>
<head>
<title>Index of /</title>
</head>
<body>
    <h1>Index of /</h1>
    <pre>
        <img src="/icons/blank.gif" alt="Icon "> <a href="?C=N;O=D">Name</a>                    <a
            href="?C=M;O=A">Last modified</a>      <a href="?C=S;O=A">Size</a>  <a
            href="?C=D;O=A">Description</a>
        <hr>
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="berta.ear/">berta.ear/</a>          23-Sep-2014 13:17    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="egon.ear/">egon.ear/</a>          24-Oct-2014 16:04    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton01.ear/">anton01.ear/</a>             18-Dec-2014 12:03    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton02.ear/">anton02.ear/</a>             18-Dec-2014 08:38    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton03.ear/">anton03.ear/</a>             18-Dec-2014 11:43    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton04.ear/">anton04.ear/</a>             05-Dec-2014 16:02    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton05.ear/">anton05.ear/</a>             15-Sep-2014 19:22    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton06.ear/">anton06.ear/</a>             17-Dec-2014 10:50    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton07.ear/">anton07.ear/</a>             10-Dec-2014 13:02    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton08.ear/">anton08.ear/</a>             15-Dec-2014 09:30    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton09.ear/">anton09.ear/</a>             18-Dec-2014 08:47    -   
        <img src="/icons/folder.gif" alt="[DIR]"> <a href="anton10.ear/">anton10.ear/</a>             18-Dec-2014 11:11    -   
        ....
        </pre>

所以现在我试图获得<a href=...的信息,但只针对那些在<img src=".." alt="[DIR]">...之后的信息

所以我创建了一个XPath,如下所示:

tester.getElementsByXPath("/html/body/pre/*[self::img[@alt='[DIR]']]");

上面只给出<img ...>元素。但我需要的是<a href=""..>元素

有人知道我做错了什么吗


共 (0) 个答案