我想批量下载一些图片库。这些图像是免费提供的,不需要任何权限。我一辈子都无法让它发挥作用。这就是我到目前为止所拥有的。$pattern 吐出的是整个 HTML 行,而不仅仅是图像链接。你有什么可以给我的指点吗?循环设置为仅运行一次以进行测试。循环将遍历所有按数字组织的页面。
# Variables
$i=1 # Webpage Counter
$j=1 # Image Counter
$rootDir = "http://website.com/sport/galleries/"
$saveDir = "C:\Users\user\Desktop\"
$webpagetxt = "C:\Users\user\Desktop\page.txt"
$links = "C:\Users\user\Desktop\links.txt"
$regex = "http://website.com/galleries/[0-9]*/[^\.]*.JPG"
# Create folder to download to
#New-Item -Name SiouxSportsGalleries -ItemType directory
# Start Web Client
$client = New-Object System.Net.WebClient
# Main loop to get image links and download
For($i=10; $i -le 10; $i++){
# Download source code of the web page.
$url = $rootDir+$i+'.htm'
$webclient = new-object System.Net.WebClient
$webpage = $webclient.DownloadString($url)
$webpage > "$webpagetxt"
# Parse web page and find image link.
$pattern = Get-Content $webpagetxt | Select-String -pattern $regex -Allmatches
echo "This is the link" $pattern
#$pattern > $links
}