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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:53:28+00:00 2026-05-31T05:53:28+00:00

What XPath query could I use to solve the below. I’m actually using nokogiri

  • 0

What XPath query could I use to solve the below. I’m actually using nokogiri (in ruby) so ideally the answer would be in the form of a ruby nokogiri form, but else just XPath and I can adapt in.

Required Output

I’m seeking to parse the below HTML (a full html page, but I’ve just copy/pasted the relevant part for clarity), and end up with basically the following:

Phone Number   Plan ID
545454545      12345
3434343434     67890

So in the context of Ruby/nokogiri this could be in a Hash for example:

% result = { "545454545" => "12345",  "3434343434" => "67890" }

HTML to be Parsed

.
.
.
<form method="post">
   <div style='line-height:18px;background-color:#FFFFFF;border: 1px #dedede solid;padding:10px;'>
   <table width='90%' border=0>
      <tr>
         <td width='30%'> Plan ID </td>
         <td width='70%'> 12345 </td>

      </tr>
      <tr>
         <td> Phone Number </td>
         <td> 545454545 </td>
      </tr>
      .
      .
      .
      </table>
   </div>
   <br>
   .
   .
   .
   <div style='line-height:18px;background-color:#FFFFFF;border: 1px #dedede solid;padding:10px;'>
   <table width='90%' border=0>
      <tr>
         <td width='30%'> Plan ID </td>
         <td width='70%'> 67890 </td>

      </tr>
      <tr>
         <td> Phone Number </td>
         <td> 3434343434 </td>
      </tr>
      .
      .
      .
      </table>
   </div>
   <br>
  • 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-31T05:53:30+00:00Added an answer on May 31, 2026 at 5:53 am

    Assuming those lines you’ve replaced with periods do not contain data you want to collection, which would mean each table provided a unique result set, the following would work:

    #!/usr/bin/env ruby
    
    require 'nokogiri'
    
    doc = Nokogiri.HTML DATA.read
    results = {}
    
    doc.search('table').each do |table|
      plan_id = table.at('tr[1]/td[2]')
      phone_number = table.at('tr[2]/td[2]')
    
      if plan_id && phone_number
        results[phone_number.text.strip] = plan_id.text.strip
      end
    end
    
    p results #=> {"545454545"=>"12345", "3434343434"=>"67890"}
    
    __END__
    <form method="post">
       <div style='line-height:18px;background-color:#FFFFFF;border: 1px #dedede solid;padding:10px;'>
       <table width='90%' border=0>
          <tr>
             <td width='30%'> Plan ID </td>
             <td width='70%'> 12345 </td>
    
          </tr>
          <tr>
             <td> Phone Number </td>
             <td> 545454545 </td>
          </tr>
          .
          .
          .
          </table>
       </div>
       <br>
       .
       .
       .
       <div style='line-height:18px;background-color:#FFFFFF;border: 1px #dedede solid;padding:10px;'>
       <table width='90%' border=0>
          <tr>
             <td width='30%'> Plan ID </td>
             <td width='70%'> 67890 </td>
    
          </tr>
          <tr>
             <td> Phone Number </td>
             <td> 3434343434 </td>
          </tr>
          .
          .
          .
          </table>
       </div>
       <br>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following XPATH Query to list the object under a site. ListObject[@Title='SomeValue']
What would be the xpath query to find all child nodes with a specific
What XPath query should I use to get to the GetLogisticsOfferDateResult Node? I have
With the following XML: <parent> <child>Stuff</child> <child>Stuff</child> </parent> Using XPath I query the child
i used to select table with class name list. I use this xpath query
I am using the following XPath query to search the name of the author
I have a simple XML and i signed the XML using XPATH query like
I'm using nokogiri to select the 'keywords' attribute like this: puts page.parser.xpath(//meta[@name='keywords']).to_html One of
I am having to write a XPath Query to pull out the answer for
I have the following xpath query which seems to be working but I just

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.