Jump to content

Parse bus plan


cordoprod

Recommended Posts

Hi,

I am developing an app for iPhone and for the parsing part and getting the data I need PHP.

I have managed to parse somethings, but the times when the bus arrives i haven't managed to do.

 

This is the site i need to parse:

http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/t/01-100.htm

 

there are two tabs on this page. #1 is Tur, and #2 is Retur. These tabs are when the bus drives, and when it comes back.

 

These tabs are powered by javascript, and there is a <div> that managed those two. How can i parse the source so i start at <div id="tab1"> and end it where that div is ended.

 

It's so i can seperate these two, so i know which one is Tur and Retur.

Link to comment
https://forums.phpfreaks.com/topic/186015-parse-bus-plan/
Share on other sites

The easiest and safest method by far is to use a HTML DOM Parser Class. (Some Free, Some Commercial).

 

This page coud help you a little:

http://www.onderstekop.nl/articles/114/

 

If the link get's removed then just google PHP HTML PARSER

 

Good Luck

-CB-

Link to comment
https://forums.phpfreaks.com/topic/186015-parse-bus-plan/#findComment-982285
Share on other sites

Ok i tested your suggestion MrAdam, output is Array.

<?PHP
$content = file_get_contents("http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/t/01-100.htm");
preg_match_all('/<div id="Tab[12]"[^>]*>(.*?)<\/div>/s', $content, $matches);

echo $matches[1];
?>

 

And salathe: No, but i figured it might be easier for my needs. Further on i will need to parse all the times as you see on the page.

Link to comment
https://forums.phpfreaks.com/topic/186015-parse-bus-plan/#findComment-982320
Share on other sites

Do you need to use regular expressions for this? It would be much easier using a proper parser.

I already explained this to the OP when they asked about getting the Bus number and names yesterday. But since nobody posted code for that method and people did post regular expressions that is what they have used.

 

Ok i tested your suggestion MrAdam, output is Array.

<?PHP
$content = file_get_contents("http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/t/01-100.htm");
preg_match_all('/<div id="Tab[12]"[^>]*>(.*?)<\/div>/s', $content, $matches);

echo $matches[1];
?>

 

And salathe: No, but i figured it might be easier for my needs. Further on i will need to parse all the times as you see on the page.

I also explained in the thread yesterday why code such as that will output the word Array and how to get around it.

Link to comment
https://forums.phpfreaks.com/topic/186015-parse-bus-plan/#findComment-982330
Share on other sites

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.