Beginner PHP XPath Text Display -
Target: Use Exax Checker / Firefox and PHP to display selective text on a webpage.
What is the PHP XPATH code needed to display only the name (text) on this page?
Using this code:
& lt ;? Php $ html = new DOMDocument (); @ $ HTML- & gt; LoadHtmlFile ('http://steamcommunity.com/profiles/76561197967713768'); $ Xpath = new DOMXPath ($ html); $ Nodelist = $ xpath- & gt; Query ("// div [@ class = 'persona_name']"); Foreign currency ($ nodelist $$) {echo $ n- & gt; NodeValue "\ N"; }? & Gt;
I get the output of " mopar410 is also played as this user: " I only call it "mopar410" . I "This user is also played as:" part
Some information can not be accessed via XML, and when I change it from top to xpath, tester in Firefox (example):
& lt; ? Php $ html = newdomdocument (); @ $ HTML- & gt; LoadHtmlFile ('http://steamcommunity.com/profiles/76561197967713768'); $ Xpath = new DOMXPath ($ html); $ Nodelist = $ xpath- & gt; Query ("/ x: html / x: body / x: div [3] / x: div [1] / x: div / x: div / x: div / x: div [3] / x: div [1 ] '] "); Foreign currency ($ nodelist $$) {echo $ n- & gt; NodeValue "\ N"; }? & Gt;
This does not work and I get an error. What is the proper way of right-clicking XPATH and viewing, then transfer that xpath to the PHP code? Warning: DOMXPath :: query (): Invalid expression on line 85 in Blahblabahah: Warning: invalid argument (foreah) Provided on Line 86 in Blahblabla for
I am new to this please help.
This is because & lt; Div class = "persona_name" & gt;
Include other nodes and texts other than the text you want, you can try using XPath expression to get only non-empty text nodes which & lt; Div class = "persona_name" & gt;
:
// div [@ class = 'persona_name'] / text () [general-location (.)]
Comments
Post a Comment