[erledigt] An die PowerShell-Freaks in diesem Forum: Hilfe, mein TF-PS funzt nicht mehr

  • Saluts PowerShell-Hoschis

    mMn., funktioniert eines meiner TöffForum-PowerShell-Scripte nicht mehr und ich weiss nicht wieso.

    Könnte einer von Euch ggf. dieses Dummy-Script unten mal testen?

    Eigentlich, will ich nichts anderes, als alle "<article>"-tags (Forum-Posts) aus dem HTML extrahieren. Doch seit dem Forums-Update scheint der HTML-Parser nicht mehr zu funktioneren, wohl weil das HTML nicht mehr "well-formatted" ist (es fehlen einige abschliessende Tags. Item, egal, nehm ich einen RegEx zum Extrahieren der <article>-tags aber nun bin ich auf etwas ganz kurioses gestossen:

    Wenn ich einen Web-Request absetze und die Response DIREKT mit RexEx parse ($webRsponse.Content), dann findet der Parser NICHTS! Wenn ich aber die Response zuerst in ein File speichere und dann das File lese, dann findet er die RegEx!

    Kurioserweise sind die zu suchenden RegEx-Strings im web response UND in der Datei enthalten.

    Kann mir jemand erklären, warum das so ist? :woozy_face::woozy_face::woozy_face:


    function foobarindeed {
       $file = "T:\Temp\Purge Daily\ParseWebPage.html"
       $url = "https://www.toeff-forum.ch/thread/13113-e-zigarette-dampfen/?pageNo=1"
       
       # connect to web page
       $WebResponse = Invoke-WebRequest $url -UseBasicParsing

       if ($WebResponse.StatusCode -eq 200) {

           # get web page content
           [string]$contentWebResponse = $WebResponse.Content

           # save web page to file
           Set-Content -Path $file -Value $contentWebResponse
           [string]$contentFile = Get-Content $file

           # define lookup pattern
           $from = "<article "
           $to = "</article>"

           # define regex pattern
           #$pattern = "(?<=<article ).*?(?=</article>)"
           #$pattern = '<article .*?</article>'
           #Write-Host $pattern
           
           $pattern = "$from.*?$to"
           Write-Host "$pattern"

           Write-Host "from pattern '$from' exists in web response: $($contentWebResponse.Contains($from))"
           Write-Host "to pattern '$to' exists in web response: $($contentWebResponse.Contains($to))"
           Write-Host "from pattern '$from' exists in file content: $($contentFile.Contains($from))"
           Write-Host "to pattern '$to' exists in file content: $($contentFile.Contains($to))"


           # lookup matches in web page content
           $matchesWebResponse = ([regex]$pattern).Matches($contentWebResponse) |  ForEach-Object { $_.Groups[1].Value }
           $matchCountWebResponse = $matchesWebResponse.length
           Write-Host "matches in web response content: $matchCountWebResponse"

           # lookup matches file content
           $matchesFile = ([regex]$pattern).Matches($contentFile) |  ForEach-Object { $_.Groups[1].Value }
           $matchCountFile = $matchesFile.length
           Write-Host "matches in file content: $matchCountFile"
         

           if ($matchCountWebResponse -eq $matchCountFile) {
               Write-Host "OK" -ForegroundColor Green
           } else {
               Write-Host "nope" -ForegroundColor Red
           }

       } else {
           Write-Host "failed to access $url!" -ForegroundColor Red
       }

       Write-Host "done!"
    }

    a.D.: Yamaha DT 125 MX :top:, Honda NSR 125 , Honda CB 250G , Honda VTR 1000 SP2

    i.B.: Kawasaki KLE 500 , Honda CBR 600 F , Honda CRF 1000L Africa Twin , Ducati Scrambler Urban Enduro :tee:

    Einmal editiert, zuletzt von Töfflibueb (28. September 2025 um 00:14)

  • Töfflibueb 28. September 2025 um 00:09

    Hat den Titel des Themas von „An die PowerShell-Freaks in diesem Forum: Hilfe!“ zu „An die PowerShell-Freaks in diesem Forum: Hilfe, mein TF-PS funzt nicht mehr“ geändert.
  • ich würde python und beautifulsoup verwenden:


    i know a place where no cars go

  • Gits ja nid!!!

    Scheisse, danke, "SingleLine" Parameter vergässe! Gopf! Mr sött nid so spät ir Nacht no Sache mache!


    Ganz fräch! MERCIIIIIIIIIIIIIIIIIII

    a.D.: Yamaha DT 125 MX :top:, Honda NSR 125 , Honda CB 250G , Honda VTR 1000 SP2

    i.B.: Kawasaki KLE 500 , Honda CBR 600 F , Honda CRF 1000L Africa Twin , Ducati Scrambler Urban Enduro :tee:

  • Töfflibueb 28. September 2025 um 20:48

    Hat den Titel des Themas von „An die PowerShell-Freaks in diesem Forum: Hilfe, mein TF-PS funzt nicht mehr“ zu „[erledigt] An die PowerShell-Freaks in diesem Forum: Hilfe, mein TF-PS funzt nicht mehr“ geändert.