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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:24:52+00:00 2026-05-11T11:24:52+00:00

I am trying to use xPath to traverse through the code of a newspaper

  • 0

I am trying to use xPath to traverse through the code of a newspaper (for the sake of practice) right now I’d like to get the main article, it’s picture and the small description I get of it. But I’m not that skilled in xPath so far and I can’t get to the small description.

withing this code:

<div class='margenesPortlet'>  <div class='fondoprincipal'> <div class='margenesPortlet'> <a href='notas/n1092329.htm' ><img id='LinkNotaA1_Foto' src='http://i.oem.com.mx/5cfaf266-bb93-436c-82bc-b60a78d21fb6.jpg' height='250' width='300' border='0' /></a>  <div class='piefoto_esto'>Un tubo de 12 pulgadas al lado de la Vialidad Sacramento que provoc&#243; el corte del servicio durante toda la ma&#241;ana y hasta alrededor de las cuatro de la tarde. Foto: El Heraldo de Chihuahua</div>  <div class='cabezaprincesto'><a href='notas/n1092329.htm' class='cabezaprincesto'  >Sin agua 8 mil usuarios</a></div> <div class='resumenesto'><a href='notas/n1092329.htm' class='resumenesto'  >La ruptura de una l&#237;nea en el tanque de rebombeo de agua Sacramento dej&#243; sin servicio a ocho mil usuarios, en once colonias del sur de la ciudad. </a></div> </div> </div>  </div> 

I’ve want to get the picture (with or without caption) and then the title of the article. These 3 things I can get by using:

//div[@class=’fondoprincipal’] <– gives me the main image and caption

//a[@class=’cabezaprincesto’]/text() <– gives me the article’s title

but I can’t get ahold of the small description which is the div with class=’resumenesto’, I haven’t tried getting anything by that id because the same id is used over and over through the rest of the HTML so it returns lots of extra items.

How can I get this particular one? and then would any of you recommend me a good way of parsing it to another webpage? I was thinking maybe php writing some html using those values but I’m not sure really…


Edit

What I mean by ‘this particular one’ is how do I get this div class=’resumenesto’, the one residing within div class=’fondoprincipal’…


Edit 2

Thank you, now xPath Traversing is a little bit more clear. But then about my second question, would any of you recommend me a good way of parsing it to another webpage? I was thinking maybe php writing some html using those values but I’m not sure really..

  • 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. 2026-05-11T11:24:52+00:00Added an answer on May 11, 2026 at 11:24 am

    You say ‘id’ of resumenesto, but in your code example the div you’re talking about has a class of resumenesto.

    Further, when you use an xpath of something like this:

    //div[@class='resumenesto'] 

    What you’re getting is a list of nodes matching that xpath. So if you want to specifically refer only to a single item in that list, you need to specify which item in the list:

    //div[@class='resumenesto'][1] 

    Further, what do you mean by ‘this particular one’? The only way to tell xpath specificity is to give it context, for instance ‘the div with class resumenesto that resides within some other div’, or ‘the first of the divs with class resumenesto’.

    Read W3Schools’ overview of XPath syntax for some more info.

    Edit:

    To get the div residing within ‘fondoprincipal’:

    //div[@class='fondoprincipal']//div[@class='resumenesto'] 

    This tells xpath to find any descendant div with class fondoprincipal within the document, and within that div, find any descendant div with class resumenesto.

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

Sidebar

Related Questions

I'm trying to use DOMParser, or XPath to get a XML fragment out of
I'm trying to figure out how to use XPath to get the exceptionID and
So I have some perl code that goes something like: use strict; use XML::XPath;
I'm trying to use xpath to get the contents of a table. The table
I'm trying to use XPath in PHP and I get too many elements. This
I am trying to use XPath to extract some HTML tags and data and
I'm trying to use XPath to select the items which have a facet with
I am trying to run a Perl file I created. use XML::XPath; use XML::XPath::XMLParser;
I'm trying to understand and XPath that was sent to me for use with
I am trying to get my Xpath query to output to new cell rows

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.