为了,我必须:
1)从 txt 文件中获取所有链接
http://example1.htm
http://example2.htm
http://example3.htm
...
2) 从每个链接获取源代码
3) 从源代码获取我的字符串
4) 将字符串导出到 csv
它适用于一个链接。例子:
$topic1 = "kh_header.><b>((?<=)[^<]+(?=</b>))"
$topic2 = "<b>Numer ogłoszenia:\s([^;]+(?=;))"
Select-String -Path strona1.htm -pattern $topic1 | foreach-object {
$_.line -match $topic1 > $nul
$out1 = $matches[1]
}
Select-String -Path strona1.htm -pattern $topic2 | foreach-object {
$_.line -match $topic2 > $nul
$out2 = $matches[1]
}
echo $out1';'$out2';' | Set-content out.csv -force
, 但我无法通过 txt 文件中的许多链接获得它。我试试看:
$topic = "kh_header.><b>((?<=)[^<]+(?=</b>))"
$topic2 = "<b>Numer ogłoszenia:\s([^;]+(?=;))"
$folder = Get-ChildItem e:\sk\html
ForEach ($htmfile in $folder){
If ($_.extension -eq ".htm"){
$htmfile = ForEach-Object {
$WC = New-Object net.webclient
$HTMLCode = $WC.Downloadstring($_.fullname)
}
Select-String -Path $HTMLCode -pattern $topic | foreach-object {
$_.line -match $topic > $nul
$out1 = $matches[1]
}
Select-String -Path $HTMLCode -pattern $topic2 | foreach-object {
$_.line -match $topic2 > $nul
$out2 = $matches[1]
}
echo $out1';'$out2';' | Set-content out.csv -force
}
}
我怎么才能得到它?