Jump to content

Parse bus plan, please help.


cordoprod

Recommended Posts

Hey, i'm trying to parse a web page containing bus plans.

It is this site: http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/index/Avd_01.htm

 

What I want to parse is all the rutenr and rutenavn.

 

The plans are divided into section as you can see there are tabs on the top of the page. This does not make it easy for me, as I have to separate them.

 

Here is what I managed to pull out:

http://ruteinfo.cordoproduction.com/hent_ruter.php?avdeling=01&fylke=Ostfold

 

Here is my code:

$htmlCode = file_get_contents("http://www.rutebok.no/NRIIISStaticTables/Tables/ruter/index/Avd_".$avdeling.".htm");

$linjer = preg_match_all('/\["([\pL ]+)",/', $htmlCode, $linjerMatches);
//$type = preg_match_all('/(.*\/images\/)(.*)(-s.gif)/', $htmlCode, $typeMatches);
$tabeller = preg_match_all('/(.*\d\d\-\d\d\d\.htm">)(\d\d\-\d\d\d)(.*px">)(.*)(<\/td>.*)/', $htmlCode, $matches);

foreach($linjerMatches[1] as $k=>$v) {
echo '<h2>' . $linjerMatches[1][$k] . '</h2>';	

foreach($matches[2] as $key=>$value) {
   		if(mysql_num_rows($checkResult) == 0) { 
		echo '<b>' . $value . '</b> ' . $matches[4][$key] . ' <b>' . $linjerMatches[1][$k] . '</b><br/>';

		//$sql = "INSERT INTO ruteinfo_ruter(fylke,linje,bussnummer,bussnavn) VALUES('".$fylke."', '".$linjerMatches[1][$k]."','".$value."', '".$matches[4][$key]."')";
		//$result = mysql_query($sql, $linkID) or die("Error");
	}
}
}

 

My problem is that in each section (tab) all the results appear, from every tab. Like in the tab called Halden the results from Sarpsborg appears as well.

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.