Contenidos
Leer de un fichero XML todos los enlaces de un sitio web

Detectar una etiqueta HTML que contiene un código en PowerShell

Código completo que resuelve el ejercicio
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$var1 = ([xml] [System.Net.WebClient]::new().DownloadString('https://www.jesusninoc.com/sitemap.xml')) $array = "" foreach($url in $var1.sitemapindex.sitemap | select loc) { $url.loc $var2 = ([xml] [System.Net.WebClient]::new().DownloadString($ur.loc)) Start-Sleep -Seconds 5 foreach($url2 in $var2.urlset.url) { $url2.loc $result = Invoke-WebRequest $url2.loc [String]$cmdlet=$result.AllElements | Where class -eq 'crayon-pre' | %{$_.outerHTML} # IMPORTANTE INSERTAR SALTO DE LÍNEA $cmdlet = $cmdlet.Replace(" ","`n").Replace("","`n").Replace(" ","").Replace(">",">") $cmdlet = $cmdlet -replace "<.*?>" # Crear un bloque con el contenido del script [System.Management.Automation.ScriptBlock]$bloque = Invoke-Expression ("{"+ $cmdlet +"}") # Localizar los cmdlets y variables de PowerShell en el blogue de código $final = ($bloque.Ast.FindAll( { $true }, $true) | Where-Object { $_.GetType().Name -eq 'CommandAst' } | select Extent).Extent.text.split(" ")[0] +" " # Almacenar los cmdlets que hay en cada código en un fichero $final | Out-File cmdlets.txt -Append $array += $final # $bloque.Ast.FindAll( { $true }, $true) | Where-Object { $_.GetType().Name -eq 'VariableExpressionAst' } | select variablePath Start-Sleep -Seconds 1 } } |