使用Powershell从Xml站点地图下载URL
我在几个不同的网站上有一个标准的XML网站地图,等等 以标准格式使用Powershell从Xml站点地图下载URL,powershell,caching,powershell-2.0,Powershell,Caching,Powershell 2.0,我在几个不同的网站上有一个标准的XML网站地图,等等 以标准格式 <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">
<url>
<loc>http://www.example.co.uk</loc>
<lastmod>2014-07-08T08:28:26+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.3</priority>
</url>
<url>
<loc>http://www.example.co.uk/page-name</loc>
<lastmod>2013-02-05T13:36:02+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
etc....
</urlset>
http://www.example.co.uk
2014-07-08T08:28:26+00:00
每日的
0.3
http://www.example.co.uk/page-name
2013-02-05T13:36:02+00:00
每日的
0.7
等
我想能够提供一个网站地图的URL列表。并将powershell文件分别发送到每个站点
获取每个站点的站点地图xml,然后从站点地图文件中分别下载所有URL。基本上是向每个url发出请求(我不想存储下载的内容)
其思想是,在站点更新后,它将触发每个站点所有主页的缓存,因此当用户访问该站点时,他们将拥有一个缓存版本
有没有关于我该怎么做的想法?我开始尝试使用Wget,但在Win8/Server上出现了问题。因此,我认为Powershell可能是一个更好的选择。如果您可以运行powerhell V3,这里有一种方法:
iwr
是invoke-webrequest
$maps=@("http://server.com/sitemap.xml","http://server2.com/sitemap.xml")
$maps |%{
[xml]$response=iwr $_ |select -expand content
#get all urls in the sitemap
$response.urlset.url |%{
#make a get request on each url
echo "hitting : " $_.loc
iwr $_.loc |out-null
}
}
如果无法切换到V3,则必须使用.net方法,用以下模式替换iwr:
$client=New-Object system.Net.WebClient;
[xml]$response=$client.DownloadString("http://server.com/sitemap.xml")
你应该自己提供最低限度的代码…为什么?在StackOverFlow中它在哪里声明我必须这样做?