Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:23:32+00:00 2026-06-06T21:23:32+00:00

I traversed a DOM in search for images in a certain div. Ive tested

  • 0

I traversed a DOM in search for images in a certain div. Ive tested the xpath expression in Chrome and it works. Automating this in PHP is tedious, so far. When i use var_dump on the nodelist object, it seems something is inside the object: object(DOMNodeList)#11 (0) { } However, when i use nodeValue on the nodelist, i don’t get any results. My guess is because it are images, it cannot be displayed as a string, this is basically what nodeValue does. Anyone has experience with gathering images via xpath? How to retrieve the images that i’ve gathered?

$article = file_get_contents($url);

// get images from article via xpath
$html = new DOMDocument();
@$html->loadHtml($article);
$xpath = new DOMXPath($html);
$nodelist = $xpath->query('//div[@class="contentBody contentBody-collapsed morph"]//img');
var_dump($nodelist);
foreach ($nodelist as $n)
    print $n->nodeValue."<br/>\n";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:23:34+00:00Added an answer on June 6, 2026 at 9:23 pm

    Try e.g.:

    print $n->getAttribute('src');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small Chrome extension to manipulate Google's search results' DOM to add
Using jQuery to create new DOM elements from text. Example: jQuery('<div><img src=/some_image.gif></img></div>'); When this
I have the following HTML structure, (This cannot change). <!-- Comment 1 --> <div
I am trying to traverse up the DOM to the closest DIV. The markup
I have a DOM structure below: <div class='box'> <section id=profile> <h1>testuser</h1> <div id=following> <a
jQuery is quite multifaceted when it comes to selecting certain DOM elements. Today it
I've have the following (PHP) code that traverses an entire DOM document to get
Okay, this may be a bit basic. The HTML is : <div class=parents-of-all> <p>
I'm learning how to traverse the DOM so this question is related to that.
I always hear people talk about DOM this, manipulate the DOM, change the DOM,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.