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 5929457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:25:25+00:00 2026-05-22T14:25:25+00:00

<?php $htmlget = new DOMDocument(); @$htmlget->loadHtmlFile(http://www.amazon.com); $xpath = new DOMXPath( $htmlget); $nodelist = $xpath->query(

  • 0
<?php 
$htmlget = new DOMDocument();

@$htmlget->loadHtmlFile(http://www.amazon.com);

$xpath = new DOMXPath( $htmlget);
$nodelist = $xpath->query( "//img/@src" );

foreach ($nodelist as $images){
    $value = $images->nodeValue;
}
?>

i got all images but how do i get the information around the same element the image is in? for example, on amazon.com, theres a the kindle. i have the picture now but need the information around such as the price description…
thanks

  • 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-05-22T14:25:26+00:00Added an answer on May 22, 2026 at 2:25 pm

    It depends on the markup of the requested page, here an example for getting the price on amazon:

    <?php
           $htmlget = new DOMDocument();
    
           @$htmlget->loadHtmlFile('http://www.amazon.com');
    
           $xpath = new DOMXPath( $htmlget);
           $nodelist = $xpath->query( "//img/@src" );
    
            foreach ($nodelist as $imageSrc){
    
          //fetch images with a parent node that has class "imagecontainer"
          if($imageSrc->parentNode->parentNode->getAttribute('class')=='imageContainer')
          {
            //skip dummy-images
            if(strstr($imageSrc->nodeValue,'transparent-pixel'))continue;
    
            //point to the common anchestor of image and product-details
            $wrapper=$imageSrc->parentNode->parentNode->parentNode->parentNode->parentNode;
    
            //fetch the price
            $price=$xpath->query( 'span[@class="red t14"]',$wrapper );
            if($price->length )
            {
               echo '<br/><img src="'.$imageSrc->nodeValue.'">'.$price->item(0)->nodeValue.'<br/>';
            };
          }
    }
    ?>
    

    But however, you shouldn’t parse pages that way. If they want to provide you some information, the ususally have an API. If not, they don’t want you to grab anything. Parsing that way is not reliable, the markup of the requested page can change every second(you may open a door for exploits too). It also may not be legal .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

php.ini [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = ssl://smtp.gmail.com ; http://php.net/smtp-port
PHP Code: $form = new Zend_Form(); $filters = array(new Zend_Filter_StringTrim()); $form->setElementFilters($filters); // <-- ISSUE
PHP allows you to send RAW HTTP headers, which must be sent before any
PHP scripts can continue executing after the HTTP page request , so how do
I have PHP 5.1.6 (cli) installed and whenever the GET query string is more
PHP has a great function called htmlspecialcharacters() where you pass it a string and
PHP's explode function returns an array of strings split on some provided substring. It
PHP, as we all know is very loosely typed. The language does not require
PHP stores its session information on the file system of the host of the
PHP treats all arrays as associative, so there aren't any built in functions. Can

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.