Created
September 25, 2012 07:29
-
-
Save sng2c/3780454 to your computer and use it in GitHub Desktop.
고속버스 빈자리 체크
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use utf8; | |
use LWP::UserAgent; | |
use Encode; | |
use AnyEvent; | |
binmode(STDOUT,":utf8"); | |
my $cv = AE::cv; | |
my $only_biz = 1; | |
my $timer = AE::timer 0,30,sub{buscheck()}; | |
$ua = LWP::UserAgent->new(); | |
$param = { | |
TER_FR=>'031', #동서울 | |
TER_TO=>'700', #부산 | |
Tim_date_Year=>'2012', | |
Tim_date_Month=>'09', | |
Tim_date_Day=>'29', | |
TIM_TIM_I=>'0000', | |
BUS_GRA_I=>'0', | |
pCnt_100=>'1', | |
pCnt_050=>'0', | |
pageCheck=>'0', | |
}; | |
@day = qw( 28 29 ); | |
@times = qw( 0700 1000 1300 1600 1900 2100 ); | |
sub buscheck{ | |
foreach $d (@day){ | |
print "${d}일\n"; | |
$param->{Tim_date_Day} = $d; | |
foreach $t (@times){ | |
print "\t${t}시\n"; | |
$param->{TIM_TIM_I} = $t; | |
$res = $ua->post('http://www.kobus.co.kr/web/11_Myungjul/m_reservation_1_1.jsp',$param); | |
$html = $res->content; | |
$html = Encode::decode('euc-kr',$html); | |
Encode::_utf8_on($html); | |
treat_html($html); | |
} | |
} | |
print "- http://www.kobus.co.kr/web/index.jsp -----------------------------------------------------------------------\n"; | |
} | |
sub treat_html{ | |
my $html = shift; | |
my @forms = ($html =~ /(<form name="SeatForm\d+".+?\/form>)/gs); | |
foreach my $f (@forms){ | |
#print $f; | |
if( $f =~ /value="선 택"/ ){ | |
$f =~ m!<td align="center".+?class=line_bottom>(.+?)</td>!; | |
my $type = $1; | |
next if( $only_biz == 1 && $type !~ /우등/ ); | |
$f =~ /class=line_RB>(\d\d:\d\d)</; | |
my $time = $1; | |
$f =~ m!<td align="center" class=line_bottom>(\d+)</td>!; | |
my $man = $1; | |
print "\t\t$time $type(${man}표) 예약가능\n"; | |
} | |
} | |
} | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment