perl登录whu选课系统,查看信息等

perl登录whu选课系统,查看信息等

tkorays(tkorays@hotmail.com)

永不停止地奋斗!


        曾想过用命令行来操作选课系统,这看起来多么好玩的一件事啊。

        要实现它,首先要做的就是选课系统的登录,然后是解析页面,获取信息。这些用perl实现是多么简单!


        下面实现了一个简单登录与课表查询,其他功能如查询信息,选课等,道理都是一样的。不是post就是get然后解析。


#!/usr/bin/perl

# Copyright 2014 tkorays. All rights reserved.
# author tkorays
# email tkorays@hotmail.com

use strict;
use warnings;
use LWP;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use URI::Escape;
use URI::URL;

my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0");
$ua->timeout(100);
my $cookie_jar = HTTP::Cookies->new(
	file=>'lwp_cookies.txt',
	autosave=>1,
	ignore_discard=>1);
$ua->cookie_jar($cookie_jar);

my $whu_id = '你的whu学号';
my $whu_pwd = '你的密码';
my $captcha = '';
my $url = 'http://202.114.74.198';
my $form_submit = encode('gb2312',decode('utf8',"确 定"));
my $captcha_url = $url.'/GenImg';
my $pres = $ua->get($captcha_url);
open(FILE_HANDLE,'>img.jpg');
binmode FILE_HANDLE;
print FILE_HANDLE $pres->content;
close FILE_HANDLE;

###################################
# input info
print 'input your id:',"\n";
#chomp($whu_id = <STDIN>);
die "\n***please input your id***\n" unless $whu_id;
print 'input your password:',"\n";
#chomp($whu_pwd =  <STDIN>);
die "\n***please input your password***\n" unless $whu_pwd;
print 'input captcha:',"\n";
chomp($captcha = <STDIN>);
die "\n***please input captcha***\n" unless $captcha;

my $res = $ua->post($url.'/servlet/Login',{
		'who'=>'student',
		'id'=>$whu_id,
		'pwd'=>$whu_pwd,
		'yzm'=>$captcha,
		'submit'=>$form_submit
});
if($res->header('Location') eq $url.'/stu/newstu_index.jsp'){
	print "login success!\n";
}else{
	exit;
}

# get lessons

my $lessonpage = $ua->get($url.'/stu/query_stu_lesson.jsp');
die 'failed to open lesson page' unless $lessonpage->is_success;
my $pagect = $lessonpage->content;
$pagect =~ s/[\r\n\t]/ /g;
my $result;
my $t = encode('gb2312',decode('utf8',"姓名"));
$pagect =~ /$t:(.*?) /;
print "\n\n",encode('gb2312',decode('utf8',"姓名")),": $1\n";
$t = encode('gb2312',decode('utf8',"学号"));
$pagect =~ /$t:(.*?)\s/;
print encode('gb2312',decode('utf8',"学号")),": $1\n";


print encode('gb2312',decode('utf8',"课程")),": \n";
my @allmatch = $pagect =~ /<tr[^>]*>(.*?)(?!\/tr>)<\/tr>/g;
foreach my $single(@allmatch){
	$result = $single =~ /<td width="80">(.*?)(?!\/td>)<\/td>/g;
	print $1,"\n" if $result;
}

        填写好密码,找到验证码文件填写好后,运行结果如下:





        之后你就可以为所欲为,编写自己的选课系统功能,自由选课,一键评教,抢课,so easy……


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值