返回列表 发帖

【完结】50元求文字提取

本帖最后由 lxh623 于 2023-4-28 06:56 编辑

当前文件夹有许多子文件夹,其下都有子文件夹OEBPS,OEBPS下又有子文件夹juans。子文件夹juans含有一个或者多个xhtml文件。
在子文件夹juans的每一个xhtml文件中,用正则表达式提取<span class\="text\_2"><span class\="corr">(.{1,2})<\/span>,把提取的文本\1写入在子文件夹juans中新建的Cbeta.txt,编码是UTF-8,一行一个。
谢谢!

<span class='corr'><span class="text_1">準提心要</span></span>
???
你确定你的要求是对的?
你好

TOP

準提心要
???
你确定你的要求是对的?
jyswjjgdwtdtj 发表于 2023-4-27 19:11

好像你下载了文件。
txt_1和txt_2,你没有分清吧。
当然,也许说的不完全清楚。
就是一行得到一个字。
谢谢!

TOP

额 其实正则提取是蛮简单的 就是你这些奇怪的字符都是属于什么编码?我要知道正确的编码才能读到正确的内容
你好

TOP

<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
path %SYSTEMROOT%\System32\WindowsPowerShell\v1.0;%path%
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
pause
exit
#>
$current=($env:current).trimend('\');
$enc=New-Object System.Text.UTF8Encoding $False;
$folders=@(dir -literal $current -recurse|?{$_ -is [System.IO.DirectoryInfo]});
for($i=0;$i -lt $folders.length;$i++){
    if($folders[$i].Name -eq 'juans'){
        write-host $folders[$i].FullName -ForegroundColor yellow;
        $arr=New-Object -TypeName System.Collections.ArrayList;
        $files=@(dir -literal $folders[$i].FullName|?{('.xhtml' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
        for($j=0;$j -lt $files.length;$j++){
            write-host $files[$j].Name;
            $text=[IO.File]::ReadAllText($files[$j].FullName, $enc);
            $m=[regex]::matches($text, '<span class="text_2"><span class="corr">(.+?)</span>');
            foreach($it in $m){
                [void]$arr.add($it.groups[1].value);
            }
        }
        $newfile=$folders[$i].FullName+'\Cbeta.txt';
        [IO.File]::WriteAllLines($newfile, $arr, $enc);
    }
}COPY
1

评分人数

提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 5# zaqmlp
请查收。
谢谢!

TOP

返回列表