Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
使用xPath解析元标记_Xpath_Xml Parsing_Web Scraping - Fatal编程技术网

使用xPath解析元标记

使用xPath解析元标记,xpath,xml-parsing,web-scraping,Xpath,Xml Parsing,Web Scraping,如何解析元标记,例如 <meta itemprop="email" content="email@example.com" class=""> 请告知 非常感谢itemprop=“email”属性在整个网页中可能是唯一的。在这种情况下,您可以通过其XPath访问content属性来选择电子邮件,如下所示: //meta[@itemprop="email"]/@content 如果itemprop=“email”不是唯一的,您可以通过选择id等于businessdetailspr

如何解析元标记,例如

<meta itemprop="email" content="email@example.com" class="">
请告知


非常感谢
itemprop=“email”
属性在整个网页中可能是唯一的。在这种情况下,您可以通过其
XPath
访问
content
属性来选择电子邮件,如下所示:

//meta[@itemprop="email"]/@content

如果
itemprop=“email”
不是唯一的,您可以通过选择
id
等于
businessdetailsprismary
的元素,使您的
XPath
更加具体:

//*[@id="businessDetailsPrimary"]//meta[@itemprop="email"]/@content

非常感谢您的及时回复。它工作得很好。还有一件事,我也尝试使用xPath提取地址,但地址在页面中的位置并不总是相同的,例如:……有什么方法可以处理这种情况吗?
//*[@id="businessDetailsPrimary"]//meta[@itemprop="email"]/@content