- #!/usr/bin/perl -w
- ######################## 鏈接數據庫, 將數據庫中查找出來的 城市 中文名字和 英文名字 分別放到數組
- use DBI;
- use DBD::mysql;
- # 鏈接數據庫,地址 帳戶 密碼
- my $dbh = DBI -> connect("DBI:mysql:db_iplocate;host=127.0.0.1", "admin","admin",{RaiseError=>1});
- # sql命令
- my $sth = $dbh->prepare( q{select city_cn,city_en from `gps`}) or die("Cannot prepare statement:", $dbh->errstr(),"\n");
- # 執行sql命令
- my $rc = $sth->execute() or die("Cannot execute statement:", $sth->errstr(), "\n");
- # 初始化兩個數組,未來用來裝 城市的 中文名字 和 英文名字
- my @city_cn;
- my @city_en;
- # 將從mysql獲得的city_cn和city_en放到相應的數組中
- while (my @row = $sth -> fetchrow_array()){
- push @city_cn,$row[0];
- push @city_en,$row[1];
- }
- warn($DBI::errstr) if $DBI::err;
- $dbh->disconnect();
- $sth->finish();
- ####################### 按照每一個 城市 3個運營商進行生成 相應的命令, 並執行相應的命令,將下載的東西放到 當前目錄的
- # 初始化兩個數組, 用來裝 運營商的 中文名字 和英文名字
- my @isps_cn = ("移動","聯通","電信");
- my @isps_en = ("ChinaMobile","ChinaUnicom","ChinaTelecom");
- foreach $i(0..(@city_cn-1)){
- foreach $j(0..2) {
- $page_url = 'wget http://www.5maila.com/ipa.php?' . "$city_cn[$i]" .'%20' . "$isps_cn[$j]" . ' -O ' . "$city_en[$i]" ."_". "$isps_en[$j]" ;
- print `$page_url`;
- }
- }