Questions tagged [domxpath]

domxpath is a class in PHP's DOM API to support XPATH 1.0

domxpath called the DOMXPath is a class in PHP's DOM API that support XPATH 1.0. It provides functions to run XPATH queries on the document and retrieve specific parts of the document

492 questions
2
votes
1 answer

PHP DOMXPath query using the innerHTML/nodeValue of an element to find and return the element

Can you please help me with the correct syntax to use when you want to check the innerHTML/nodeValue of an element? I have no problem with the Name however the Age is within a plain div element, What is the correct syntax to use in place of "NOT…
Craig
  • 2,093
  • 3
  • 28
  • 43
2
votes
2 answers

How to ignore/continue if TD does not contain an image?

I need to continue; if TD does not contain an image. I tried this: if(!$image){continue;} but that did not work.
al-dr
  • 147
  • 1
  • 3
  • 10
2
votes
3 answers

Remove


with DOMxpath or regex?

I use DOMxpath to remove html tags that have empty text node but to keep
tags, $xpath = new DOMXPath($dom); while(($nodeList = $xpath->query('//*[not(text()) and not(node()) and not(self::br)]')) && $nodeList->length > 0) { foreach…
Run
  • 54,938
  • 169
  • 450
  • 748
2
votes
1 answer

XPath command to get only a specific element data and not others

Suppose I have an XML file - 2021 Porsche 911 2020 Porsche 911…
Mud
  • 21
  • 5
2
votes
1 answer

XPath find attributes with empty value

I load html using DOMDocument and then apply DOMXPath filters on it. Does any of these objects have a way to distinguish attribute with empty string value and attribute without a value? I know in both cases the…
Jan Turoň
  • 31,451
  • 23
  • 125
  • 169
2
votes
1 answer

PHP XPath to determine if a checkbox is checked?

On a website it has a checkbox HTML code like this: How do I check if the checkbox is already checked via the xPath? I essentially just want a boolean telling…
Yuri
  • 89
  • 1
  • 1
  • 9
2
votes
0 answers

Google Chrome: Is it possible to copy XPath dynamically (in code)?

In google chrome, you can get the xpath of an element via if you right click on an element -> copy xpath: Here is how GIF QUESTION: Is it possible to dynamically access an xpath generated by Chrome using some Chrome Api (?) / Functions. I want to…
Shaz
  • 1,443
  • 1
  • 27
  • 67
2
votes
1 answer

PHP DOMDocument And DOMXpath

I am trying to find the last paragraph tag in a block of HTML using DOMDocument/DOMXpath but can't seem to figure it out. # Create DOMDocument Object $dom = new DOMDocument; # Load HTML into DomDocument Object …
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
2
votes
1 answer

PHP DOMXPath problem

$xpath = new DOMXpath($doc); $res = $xpath->query(".//*[@id='post2679883']/tr[2]/td[2]/div[2]"); foreach( $res as $obj ) { var_dump($obj->nodeValue); } I need to take all the items in the id with the word "post". Example:
Kirill Firsov
  • 509
  • 1
  • 7
  • 16
2
votes
1 answer

PHP + Wikipedia: Get content from the first paragraph in a Wikipedia article?

I’m trying to use Wikipedia’s API (api.php) to get the content of a Wikipedia article provided by a link (like: http://en.wikipedia.org/wiki/Stackoverflow). And what I want is to get the first paragraph (which in the example of the Stackoverflow…
2
votes
1 answer

DOMXPath - query

XML File: Root element 4 1 5
user269867
  • 3,266
  • 9
  • 45
  • 65
2
votes
2 answers

XPath syntax, with or without "/text()" suffix

From different websites, the XPath syntax provided are different, primarily the need of the "/text()" suffix. Citing syntax without the need of suffix: https://www.w3schools.com/xml/xpath_syntax.asp https://www.javatpoint.com/xpath-syntax Citing…
2
votes
1 answer

Using DOMXpath to catch all team names from a page in PHP

I'm would like to extract all the team name and link from this page: https://www.transfermarkt.fr/ligue-1/startseite/wettbewerb/FR1 I'm using DOMXpath to match element but with the following code it do not return me anything. function…
PacPac
  • 267
  • 2
  • 8
2
votes
1 answer

XPath expression to get a string after a
tag

I'm trying to get the content in article/div/p but only the date after the
tag. How is that done?

Man rescued after falling into Crater Lake

Man rescued after falling 800 feet…

Karl Hill
  • 12,937
  • 5
  • 58
  • 95