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
Share on other sites

You could use a regular expression to parse the two div's content:

 

preg_match_all('/<div id="Tab[12]"[^>]*>(.*?)<\/div>/s', $str, $matches);

 

Edit: When I started writing that the last 2 posts weren't there and it made more sense to your OP.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.