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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:24:26+00:00 2026-05-25T10:24:26+00:00

I need to scrape some website data from a table on a website and

  • 0

I need to scrape some website data from a table on a website and create an XML document that will be used by an app.

The table looks like this:

<table id="results" class="results">
        <thead>
            <tr>
                <th scope="col" class="resRoute">Route</th>
                <th scope="col" class="resDir">To</th>
                <th scope="col" class="resDue sorted">Time</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="resRoute">263</td>
                <td class="resDir">Route Name</td>
                <td class="resDue">1 min</td>
            </tr>
            <tr>
                <td class="resRoute">17</td>
                <td class="resDir">Route Name</td>
                <td class="resDue">2 min</td>
            </tr>
        </tbody>
    </table>

And I would like to create an XML feed that looks like this:

<train>
    <route>263</route>
    <direction>Route Name</direction>
    <due>2 Min</due>
</train>
<train>
    <route>17</route>
    <direction>Route Name</direction>
    <due>12 Min</due>
</train>
  • 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-25T10:24:26+00:00Added an answer on May 25, 2026 at 10:24 am

    Hack hackedy hack hack hack!

            $html = '<table id="results" class="results">
                <thead>
                    <tr>
                        <th scope="col" class="resRoute">Route</th>
                        <th scope="col" class="resDir">To</th>
                        <th scope="col" class="resDue sorted">Time</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="resRoute">263</td>
                        <td class="resDir">Route Name</td>
                        <td class="resDue">1 min</td>
                    </tr>
                    <tr>
                        <td class="resRoute">17</td>
                        <td class="resDir">Route Name</td>
                        <td class="resDue">2 min</td>
                    </tr>
                </tbody>
            </table>
        ';
    
        $body = explode('<tbody>', $html);
    
        $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><xml />");
    
        $rows = array();
        foreach (array_slice(explode('<tr>', end($body)), 1) as $row)
        {
            preg_match('/resRoute">([0-9]+)<\/td>/', $row, $ids);
            preg_match('/resDir">([^<]+)<\/td>/', $row, $dir);
            preg_match('/resDue">([^<]+)<\/td>/', $row, $due);
    
            $node = $xml->addChild('train');
    
            $node->addChild('route', $ids[1]);
            $node->addChild('direction', $dir[1]);
            $node->addChild('due', $due[1]);
        }
    
        header('Content-Type: text/xml');
        echo $xml->asXML();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to scrape some data from webpages. But I have some encoding problems
I am trying to scrape some data from a page with a table based
I need to scrape from a website that requires authentication, that is a user
I would like to scrape some dynamic data off of a website. On the
I need to scrape some websites, and would like to avoid downloading images from
I need to scrape some content from a HTTP response with Java. The required
I'm trying to page scrape some DOM that looks like this: <span>text</span> and sometimes
I am working on a little test app to scrape some data (in this
I'm scraping some data from the frontpages of a list of website domains. Some
I need a javascript function to automatically login and then scrape some detail from

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.