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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:32:39+00:00 2026-06-05T03:32:39+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 or JSON document that will be used by an app. and i have some problem getting the below data.

The table looks like this:

<table border="0" cellpadding="3" cellspacing="0" bgcolor="#DDEEFF" width="100%">
<tr>
<td width="20%" ><font face="Verdana, Arial" size="1">SRC</a></td></font>
    <td width="58%" ><font face="Verdana, Arial" size="1"><a href="http://example.com/this/news?id=1&by=today" onMouseOver="a('Open Bulletin');return true" onMouseOut="b()">Welcome</font></a></td>
<td width="17%" align="center"><font face="Verdana, Arial" size="1">Event</td></font>
    </tr>   

<tr>
<td width="20%" ><font face="Verdana, Arial" size="1">FMD</a></td></font>
    <td width="58%" ><font face="Verdana, Arial" size="1"><a href="http://example.com/this/news?id=2&by=today" onMouseOver="a('Open Bulletin');return true" onMouseOut="b()">Another News</font></a></td>
<td width="17%" align="center"><font face="Verdana, Arial" size="1">Updates</td></font>
    </tr>   
</td>

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

<bulletins>
    <title>Welcome</title>
    <id>1</id>
    <type>News</type>
</bulletins>

<bulletins>
    <title>Another News</title>
    <id>2</id>
    <type>Updates</type>
</bulletins>

Here is my current code :

<?php
$body = explode('<table border="0" cellpadding="3" cellspacing="0" bgcolor="#DDEEFF" width="100%">', $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('#<a.*?href="(.*?)".*?>(.*?)</a>#i', $row, $title);
    preg_match('/<a.*href="(.*)".*>(.*)<\/a>/iU', $row, $id);
   // preg_match('/type">([^<]+)<\/td>/', $row, $type); 

    $node = $xml->addChild('bulletins');

    $node->addChild('title', $title[1]);
    $node->addChild('id', $id[1]);
   // $node->addChild('type', $due[1]);
}

header('Content-Type: text/xml');
echo $xml->asXML();
?>

But the problem i got this

<xml>
    <bulletins>
        <title>http://example.com/this/news?id=1</title>
        <id>http://example.com/this/news?id=1</id>
    </bulletins>
    <bulletins>
        <title>http://example.com/this/news?id=2</title>
        <id>http://example.com/this/news?id=2</id>
    </bulletins>
</xml>
  • 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-06-05T03:32:41+00:00Added an answer on June 5, 2026 at 3:32 am

    Here’s a quick example to get you started using only dom functions:

    $dom = new DOMDocument();
    @$dom->loadHTMLFile(url);
    $xpath = new DOMXPath($dom);
    
    $xml = new DOMDocument();
    foreach($xpath->query('//table/tr') as $tr) {
      $bulletin = $xml->appendChild($xml->createElement("bulletin"));
      $title = $xpath->query('.//td[2]//a', $tr)->item(0)->nodeValue;
      $bulletin->appendChild($xml->createElement("title",$title));
      $type = $xpath->query('.//td[3]/font', $tr)->item(0)->nodeValue;
      $bulletin->appendChild($xml->createElement("type",$type));
    }
    echo $xml->saveXML();
    
    • 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 a page that doesn't belong to my
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'm trying to build an android app that will log into a website, scrape
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 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

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.