• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0

PHP DOM-Document and XPath : fetch class data

Question

tarifa    0

hello dear community,

 

 

I've been having an issue trying to parse text in a span cass with DOM. Here is my code example. try to extract some lines out of a webpage - with following technique: with the Extraction of values of attributes of elements with DOMDocument

Here is what i have gathered and learned:

 

$remote = "http://website.com/"; $doc = new DOMDocument(); @$doc->loadHTMLFile($remote); $xpath = new DOMXpath($doc); $node = $xpath->query('//span[@class="user"]'); echo $node;

 

and this returns the following

 

error -> "Catchable fatal error: Object of class DOMNodeList could not be converted to string". 

 

 

I am so lost..

 

What I am trying to do is parse the user name between this tag;

 

<div class="widget plugin-meta"> <h3 class="screen-reader-text">Meta</h3>

 

see more below:

 

Here the concrete example view-source: https://wordpress.org/plugins/participants-database/ and https://wordpress.org/plugins/participants-database/

 

goal  i need the following data:

 

Version: Last updated: Active installations: Tested up:

 

view-source: https://wordpress.org/plugins/participants-database/

 

Proceedings; i checked the source of the webpage. i tried to find out whether the texte is related to some kind of pattern.i have looked closely and found that all of them have class=”widget plugin-meta”. Well - This will make extracting them, a piece of cake. I tried with the code below helps to filter html elements based on values of attributes.

 

but unfortunatly this ends up in a bad result; i need a helping hand and need to know how to parse the above mentioned data

goal: i need the following data: Version: Last updated: Active installations: Tested up:

 

any ideas!?

 

Edited by tarifa

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
+Human.Online    8,610

echo $node->nodeValue;

 

Share this post


Link to post
Share on other sites
  • 0
+Human.Online    8,610

Didn't help?  No response?

Share this post


Link to post
Share on other sites
  • 0
DaveLegg    1,012
23 hours ago, Human.Online said:

echo $node->nodeValue;

 

$node is a list of matching nodes, not a single node, so you'll need to loop over the list, and echo for each one

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
+Human.Online    8,610
5 hours ago, DaveLegg said:

$node is a list of matching nodes, not a single node, so you'll need to loop over the list, and echo for each one

Didn't notice that, yeah!

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.