我想从包含多个URL的网页中提取URL,并将提取的URL保存为txt文件.
网页中的URL以‘127.0.0.1’开头,但我想从它们中删除‘127.0.0.1’,只提取URL.当我运行下面的ps脚本时,它只保存‘127.0.0.1’.请帮我解决这个问题.
$threatFeedUrl = "https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate versions Anti-Malware List/AntiMalwareHosts.txt"
# Download the threat feed data
$threatFeedData = Invoke-WebRequest -Uri $threatFeedUrl
# Define a regular expression pattern to match URLs starting with '127.0.0.1'
$pattern = '127\.0\.0\.1(?:[^\s]*)'
# Use the regular expression to find matches in the threat feed data
$matches = [regex]::Matches($threatFeedData.Content, $pattern)
# Create a list to store the matched URLs
$urlList = @()
# Populate the list with matched URLs
foreach ($match in $matches) {
$urlList += $match.Value
}
# Specify the output file path
$outputFilePath = "output.txt"
# Save the URLs to the output file
$urlList | Out-File -FilePath $outputFilePath
Write-Host "URLs starting with '127.0.0.1' extracted from threat feed have been saved to $outputFilePath."