pb_ng
pb_ng

Reputation: 361

Parsing Meta Tag using xPath

How can I parse a Meta Tag such as

<meta itemprop="email" content="[email protected]" class="">

..and extract the email out of it.

When I copy the xPath of this tag, I get the following, which doesn't work

//*[@id="businessDetailsPrimary"]/div[2]/div/meta

Please advise.

Many thanks

Upvotes: 1

Views: 2918

Answers (1)

gtlambert
gtlambert

Reputation: 11961

The likelihood is that the itemprop="email" attribute will be unique across the webpage. In this case, you can select the email by accessing the content attribute via its XPath as follows:

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

Demo

In case itemprop="email" is not unique, you can make your XPath more specific by selecting the element with id equal to businessDetailsPrimary first:

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

Demo

Upvotes: 3

Related Questions