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
Php Xpath联合多个查询_Php_Xpath_Web Scraping - Fatal编程技术网

Php Xpath联合多个查询

Php Xpath联合多个查询,php,xpath,web-scraping,Php,Xpath,Web Scraping,我正在从另一个网站取消工作。当用户复制粘贴数据和结构更改时,源网站有不同的情况 案例1: <h3>Job Description</h3> <div style="text-align: justify; line-height: 115%"><b> Receptionist is assigned for ANAFAE-ALC based in Mazar-e-Sharif. This position is supervised by and

我正在从另一个网站取消工作。当用户复制粘贴数据和结构更改时,源网站有不同的情况

案例1:

<h3>Job Description</h3>
<div style="text-align: justify; line-height: 115%"><b>
Receptionist is assigned for ANAFAE-ALC based in Mazar-e-Sharif. This position is supervised by and reports to ALC Educational Program Manager and following are the main duties but are not limited to that.</div>

XPath表达式选择前面有
且文本节点等于“职务描述”的文本节点。这只与第三种情况相匹配,因为前两种情况分别在
之后有一个

您可以尝试以下方法:

//node()[preceding-sibling::*[1][self::h3 = "Job Description"]]/string()
一些细节:

//node()
从初始上下文中选择所有元素或文本节点子体

前面的同级::*[1]
选择紧靠前面的第一个元素

[self::h3=“Job Description”]
检查元素是否为
,其字符串值是否等于“Job Description”


/string()
返回上下文节点的字符串值。对于示例内容,可以使用
/genderant或self::text()
。如果是文本节点,则选择上下文节点;如果是元素,则选择所有后代文本节点。但是,如果将
更改为具有混合内容(即,散布有文本节点的子元素),则该表达式将返回一系列子文本节点,而
/string()
将它们连接在一起。

它不会返回任何内容。这是我现在拥有的全部字符串
//node()[前面的同级::*[1][self::h3=“作业描述”]]/后代或self::text()和后面的同级::h3[text()=“作业要求”]]
XPath表达式的执行环境是什么?您是如何运行此功能的?此功能:
//node()[previous::h3[node()=“联系人信息”]
<h3>Job Description</h3>
Receptionist is assigned for ANAFAE-ALC based in Mazar-e-Sharif. This position is supervised by and reports to ALC Educational Program Manager and following are the main duties but are not limited to that.
//text()[preceding::h3[text()="Job Description"]
//node()[preceding-sibling::*[1][self::h3 = "Job Description"]]/string()