traffic perl help?

Forum regarding Linux Software and Home Automation Domotica.
Post Reply
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

traffic perl help?

Post by Snelvuur »

All,

it seems if you register on http://www.trafficnet.nl/default.asp , you can have a nice indication on the amount of traffic and how long the traffic is.

If you then go to the page again, you dont have to login but you still see the data so i assume it sets a cookie..

This is an example, with the page showing:
Cookie: routenet=guid=%7BB6D12C51%2D9E95%2D4146%2DBFB4%2D039F6E427012%7D; ASPSESSIONIDCCQATDRB=FDEGENNBPIPJCHFADELJIFCP

the GUID is the same as your rss url.

Only when i try to move the cookie from one place to another it does not yet seem to work.. i want to create something simple in perl for this but to no luck yet.

Anybody else feels up to it? , it looked simple in my head..

// Erik (binkey.nl)
Mhwlng
Member
Member
Posts: 172
Joined: Sun Aug 26, 2007 4:16 pm
Location: Netherlands

traffic perl help?

Post by Mhwlng »

not an exact solution to your problem,

but I display this list, which does not require a login :

http://www.vid.nl/VI/overzicht

(I also display this one-line rss feed http://www.vid.nl/VI/_rss )

Marcel
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

traffic perl help?

Post by Snelvuur »

Well yes, but you can create your OWN routes, so that you can see on 1 specific route what the amount of traffic is. Which vid does not offer..

For instance, this is my rss link which is without login, but does not show the extra time when there is traffic.. http://www.trafficnet.nl/rss.asp?guid=B ... A3E146705A

which it does once you got the cookie..

// Erik (binkey.nl)
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

traffic perl help?

Post by Snelvuur »

This is what i got sofar.. if i'am correct this will rewrite the cookie.. but it hink i'am missing something else too.

If this works i can have a light turned on or something if there is too much traffic on my route :) my routenet guid is included to test with if needed..

Code: Select all

#!/usr/bin/perl -w

use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;
use HTML::Parser;

$ua = LWP::UserAgent->new();
$ua->agent("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");

# get apiid from page
$url = "http://www.trafficnet.nl/";
$resp = $ua->request(GET $url);
die "Can't fetch $url\n" if !$resp->is_success;

# parse cookies
$cookie_jar = HTTP::Cookies->new;
$cookie_jar->extract_cookies($resp);

# add cookie value for roads
my $stripcookie = $cookie_jar->as_string;
$stripcookie =~ /Set-Cookie3:\s(.*)\spath=/;
my $session ="routenet=guid=\%7BB6D12C51%2D9E95%2D4146%2DBFB4%2D039F6E427012%7D\; $1";
print $session;

#$cookie_jar->clear;
$cookie_jar->set_cookie("$session");

# get data from page with cookies and apiid
$url = "http://www.trafficnet.nl/default.asp";
$ua->cookie_jar($cookie_jar);
$resp = $ua->request(GET $url);
die "Can't fetch $url\n" if !$resp->is_success;

$doc = $resp->content;
print $doc;
// Erik (binkey.nl)
Post Reply

Return to “Linux Forum”