yujikaido Posted April 12, 2010 Share Posted April 12, 2010 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 ?> Link to comment https://forums.phpfreaks.com/topic/198318-extract-tables-from-a-website-and-rearrange-into-a-single-table/ Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 You want all the tables or just a select few? Do you just want the ones with the names? Probably better to get the HTML, convert it to some XML and parse it from there. Link to comment https://forums.phpfreaks.com/topic/198318-extract-tables-from-a-website-and-rearrange-into-a-single-table/#findComment-1040591 Share on other sites More sharing options...
yujikaido Posted April 13, 2010 Author Share Posted April 13, 2010 It needs to look like this example. http://www.cs.iusb.edu/~rbatzing/a340/faculty.php Link to comment https://forums.phpfreaks.com/topic/198318-extract-tables-from-a-website-and-rearrange-into-a-single-table/#findComment-1040635 Share on other sites More sharing options...
yujikaido Posted April 15, 2010 Author Share Posted April 15, 2010 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 ; ?> Link to comment https://forums.phpfreaks.com/topic/198318-extract-tables-from-a-website-and-rearrange-into-a-single-table/#findComment-1042113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.