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

  • Home
  • SEARCH
  • 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 4112514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:12:20+00:00 2026-05-20T22:12:20+00:00

I am trying to get the text from a page scrape using xpath, now

  • 0

I am trying to get the text from a page scrape using xpath, now I keep getting an error returned and no idea why! – bare in mind I am a very new php user, this is for a university project that I’ve taken on and its prooving to be very challenging 😛 but hey it should be.

Heres the code,

<?php

$html = file_get_contents('http://www.amazon.co.uk/New-Apple-iPod-touch-Generation/dp/B0040GIZTI/ref=br_lf_m_1000333483_1_1_img?ie=UTF8&s=electronics&pf_rd_p=229345967&pf_rd_s=center-3&pf_rd_t=1401&pf_rd_i=1000333483&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_r=1ZW9HJW2KN2C2MTRJH60');

$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXpath($dom);

$in_stock = $xpath->query("/html/body/div[@id='divsinglecolumnminwidth']/form[@id='handleBuy']/table[3]/tbody/tr[3]/td/div/span");



?>

I get the following error…

Warning: DOMDocument::loadHTML()
[domdocument.loadhtml]: Unexpected end
tag : head in Entity, line: 2664 in
C:\xampp\htdocs\scraping\domxpath.php
on line 19

About a hundred times!

Any help really appreciated! , it must be really easy to fix 😛

  • 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-20T22:12:21+00:00Added an answer on May 20, 2026 at 10:12 pm
    $xpath = new DOMXpath($dom);
    
    $expr = "/html/body/div[@id='divsinglecolumnminwidth']/form[@id='handleBuy']/table[3]/tr[3]/td/div/span";
    $nodes = $xpath->query($expr); // returns DOMNodeList object
    // you can check length property i.e. $nodes->length
    echo $nodes->item(0)->nodeValue; // get first DOMNode object and its value
    

    Also you need to add stametent for suppressing errors. I think that for performance reasons it’s better to use absolute XPath expression, but relative //form[@id=’handleBuy’]/table[3]/tr[3]/td/div/span works as well and is more elastic.

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

Sidebar

Related Questions

Trying to get a text value either yes or no from an aspx page
I am trying to get text from a html page in shell, as part
Trying to scrape a Y! Group and I can get data from one page
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I finally succeeded in using Ajax to get SOMETHING sent from one page to
I am using code from other question and i am getting the error as
Right, I'm trying to get a label with text in it (done already obviously),
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Im trying to get into some basic JavaFX game development and I'm getting confused
Im trying to get a completly data copy from a gridview, itryed clone(), tryed

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.