Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Xpath只选择一些tr_Html_Xpath_Web Scraping - Fatal编程技术网

Html Xpath只选择一些tr

Html Xpath只选择一些tr,html,xpath,web-scraping,Html,Xpath,Web Scraping,我有这样的html代码 <table> <tr> <th><a href="example.html" title="exemple_title_th"></a><th> <td></td> <td></td> <tr> <tr> <td><a href="example2.html" ti

我有这样的html代码

<table>
<tr>
    <th><a href="example.html" title="exemple_title_th"></a><th>
    <td></td>
    <td></td>       
<tr>
<tr>
    <td><a href="example2.html" title="exemple_title_td"></a><td>
    <td></td>
    <td></td>       
<tr>
<tr>
    <td><a href="example3.html" title="exemple_title_td"></a><td>
    <td></td>
    <td></td>       
<tr>
<tr>
    <th><a href="example4.html" title="exemple_title_th"></a><th>
    <td></td>
    <td></td>       
<tr>

但是它返回第一个标记之后的所有tr,包括下面包含我不想要的th标记的tr。这段代码出了什么问题?

您的xpath,
//a[@title=“example\u title\u th”]/following::tr
,使用following axis,它应该选择文档顺序中的所有元素

要选择整个文档中没有子元素的
tr
元素,可以使用简单的xpath,如:

//tr[not(th)]
//tr[not(th)]