无聊 来个娱乐版的。在线式的。不下载到硬盘。内存存取。可以返回。不特别优化,纯属添加功能。跟WIN10学的。这些东西不想下载到硬盘。
:按两次<Enter>显示选定项的内容;按<Enter>+<BackSpace>返回上一层。不带窗口按纽的。- # 配置
- $title = 'class="title|fl print';
- $Web = New-Object System.Net.Webclient;
- $Web.Encoding = [Text.Encoding]::UTF8;
- $url = 'http://www.court.gov.cn/paper/default/index.html';
- $Master = 'http://www.court.gov.cn'
- $http = (split-path $url).Replace('\','/');
- #
- Function ANJian_ZenLi {
- Param ( [string]$url )
- [Collections.Arraylist] $arr = @();
- [Collections.Arraylist] $array = @();
- $Content = $null;
- $Page = $Web.DownloadString( $url ) -Split "`n";
-
- $array = $Page -Match $title | %{ $_.Split('"')[-1] -Replace '(</?(li|div))?>','' };
- $array.Add('') | Out-Null;
-
- $Content = $Page -Match '</div><div style' -Replace ";'>","`r`n@" -Replace '</div>',"`r`n";
- $arr = ($Content -Split "`n" -Match '^@') -NotMatch '^@<' -Replace '^@','' `
- -Replace '×','X' -Replace '“','“' -Replace '”','”' -Replace '…','…';
- $arr = $arr -notmatch '^$'; if ( $arr ) { $arr.Add('') | Out-Null };
- $array = $array + $arr;
-
- $Content = ( $Page -Match '^\s+.*</div>$') -NotMatch '<div';
- $arr = $Content -Replace '^\s+|</div>| ','' -Replace '×','X' `
- -Replace '“','“' -Replace '”','”' -Replace '…','…';
- $arr = $arr -notmatch '^$'; if ( $arr ) { $arr.Add('') | Out-Null };
- $array = $array + $arr;
-
- $arr = $Page -Match '<(div|p) style.*</(div|p)>$' | %{ $_.Split('"')[-1] -Replace '(</(p|div))?>| ','' };
- $arr = $arr -notmatch '^$'; if ( $arr ) { $arr.Add('') | Out-Null };
- $array = $array + $arr;
- $array.Add('*************************完成*************************') | Out-Null;
- '';$array;
- };
- Function InputLine {
- $num = Read-Host -Prompt "输入内容序号,1 - $n ;按<Enter>+<退格>返回上一层 按2次<Enter>显示内容";
- if ( [Console]::ReadKey($true).Key -eq 'BackSpace' ) { cls;InputPage };
- $num = $num -as [int32];
- if ( !$num -or ($num -lt 1 -or $num -gt $n) ) { CLS;'超出范围,重新输入'; InputLine };
- $Url = $XianQingArray[$num-1][0];cls;
- ANJian_ZenLi $Url;pause;cls;
- Write-Host " 第 $Number 页:如下" -fore Green;
- For ( $k =0; $k -lt $XianQingArray.Count; $k++ ) {
- ''; Write-Host " <$($XianQingArray[$k][1])> " -Fore red -NoNewLine;
- Write-Host $($XianQingArray[$k][2]) -Fore DarkYellow; '';
- };
- InputLine;
- };
- Function InputPage {
- $Specify = Read-Host -Prompt "输入某一个页面,1 - $Last ";
- [Collections.Arraylist] $XianQingArray = @();
- $Number = $Specify -as [int32];
-
- if ( !$Number -or ($Number -lt 1 -or $Number -gt $Last) ) { CLS;'超出范围,重新输入'; InputPage };
- cls; $Page = $Web.DownloadString( $PageArray[$Specify-1] ) -Split "`n";
- $Content = $Page -Match 'xiangqing';
-
- $n = 0;
- $Content | %{ $n++
- $link = $Master + $_.Split('"')[-2];
- $str = $_.Split('"')[-1] -Replace '(</(a|li))?>','';
- $XianQingArray += ,($link,$n,$str);
- };
- cls; Write-Host " 第 $Number 页:如下" -fore Green;
- For ( $k =0; $k -lt $XianQingArray.Count; $k++ ) {
- ''; Write-Host " <$($XianQingArray[$k][1])> " -Fore red -NoNewLine;
- Write-Host $($XianQingArray[$k][2]) -Fore DarkYellow; '';
- };
- InputLine;
- };
-
- $Page = $Web.DownloadString( $url ) -Split "`n";
- [int]$Last = ($Page -Match '尾页' -Replace '\D','') -join '';
- [Collections.Arraylist] $PageArray = @($url);
- (2..$Last) | %{ $PageArray += $http + '/index/page/' + "$_.html" };
-
- InputPage;
复制代码
|