Jump to content

Extract tables from a website and rearrange into a single table


yujikaido

Recommended Posts

I am working on a php file to extract tables from a website and rearrange them in a vertically stacked order of a single table.  Its for an assignment so don't just give me the answer help me find the answer.

 

I know a I need to develop a expression like preq_match() and use a maybe similar to /id=\"table1\" .+\<tbody\>(.+)\<\/tbody\>/s but not sure where to go from here. D Here is my code so far. I would appreciate any help or any suggestions. Also if you know any good examples I can learn from that would be good too.  Thank you.

 

<?php
$homepage = file_get_contents('http://www.cs.iusb.edu/people/faculty.html'); ## gets contents of website into array


preg_match('id=\"table1\".+\<tbody\>(.+)\<\/tbody\>/s',$homepage,$array); ## supposed to extract all tables in page and post to $array

print_r($array); ## print out array

?>



I am still working on this and not getting anywhere to quick. So far I can input a url and I had it to ouput the website before I started messing with the code. What I want preg_match to do is  step 1 is output only table 1 in the body of the website

http://www.cs.iusb.edu/people/faculty.html. then step 2 I want to stack it in a narrow table like this final project. http://www.cs.iusb.edu/~rbatzing/a340/faculty.php

 

I dont want to use any expression or method but preg_match and I think I need to use preg_match_all for step 2 but I am not sure. I dont want to use DOM.

 

here is my code so far. Please help a guy out. I need some guidance please.  :'( Thanks.

 

<?
$url = "http://www.cs.iusb.edu/people/faculty.html";
  $input = @file_get_contents($url) or die('Could not access file: $url');
  if preg_match("/id=\table1\" .+\<tbody\>(.+)\<\/tbody\>/s,$outp);
    
    echo $outp
   ;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.