convertfrom-text.ps1 是 的博客,用 PowerShell 把文本转成对象。
http://jdhitsolutions.com/blog/2014/02/convert-text-to-object-with-powershell-and-regular-expressions/
Set-ArrayReverse 是把数组倒转。
Write-CsdnBlogCatalogue 是主程序。有一个参数,输入需要整理的博客地址。
function Set-ArrayReverse
{
param ($arr)
if ($arr.gettype() -eq@().GetType()){
[System.Array]::Reverse($arr)
}
$arr
}
function Write-CsdnBlogCatalogue
{
param (
[string] $url = "http://blog.youkuaiyun.com/hadstj?viewmode=contents"
)
#need this function
. convertfrom-text.ps1
[string] $html = Invoke-RestMethod $url
$pattern= "<spanclass=""link_title""><ahref=""/(?<link>.*?)"">\s+(?<title>.*?)\s+</a></span>"
$data = $html | ConvertFrom-Text $pattern|
Select title, @{Name="Path";Expression={ "http://blog.youkuaiyun.com/$($_.link)"}} |
select @{Name="Content"; Expression={"<p> `r`n<atarget=""_blank"" href=""$($_.path)"">$($_.title)</a></p>"}}
$(Set-ArrayReverse $data).content | Out-File "$Home\Desktop\csdnCatalogue.txt"
}

本文介绍了一个使用PowerShell脚本整理优快云博客目录的方法,包括将文本转换为对象、获取博客链接和标题,以及创建一个包含链接和内容的文件。
5332

被折叠的 条评论
为什么被折叠?



