우선, 나는 스크립팅과 파워 쉘에 대한 멍청한 행동이다. 배우는 나의 시도, 나는 여기에서 스크립트 작업되었습니다 http://www.leeholmes.com/blog/2010/03/05/html-agility-pack-rocks-your-screen-scraping-world/
이것이 제가 지금까지 가지고있는 것입니다 :
add-type -Path 'C:\Program Files (x86)\htmlAgilityPack\HtmlAgilityPack.dll'
$doc = New-Object HtmlAgilityPack.HtmlDocument
$result = $doc.Load("C:\scipts\test.html")
$texts = $doc.DocumentNode.SelectNodes("//table[@class='dataTable']/tbody/tr/td[1]/a[1]")
$result = $texts | % {
$testText = $_
$Platform = $testtext.innertext
New-Object PsObject -Property @{ Platform = $Platform} | Select Platform
}
$result | Sort Platform | out-string
이것은 제가 찾고있는 항목을 제공합니다.
* 도전 과제 *
그 출력을 각 항목에 쉼표가 뒤에 오는 단일 문자열로 변수에 넣으려고합니다. 예를 들어 항목 1, 항목 2, 항목 3 등 ...
어떤 도움이나 설명도 나 자신을 훔쳐 보았고, 내가 찾던 것들을 반드시 견디어 내지 못했기에 감사 할 것입니다.
감사!
PowerShell 도움말 ( get-help about_join
)에서
다음 다이어그램은 조인 연산자의 구문을 보여줍니다.
<String[]> -Join <Delimiter>
문제를 해결하려면 다음을 수행해야합니다.
결합하려는 문자열을 포함하는 문자열 배열을 만듭니다.
$arrayofstrings = $result | Sort Platform | foreach-object {$_.Platform}
쉼표를 구분 기호로 사용하여 문자열을 결합하십시오.
$joinedstring = $arrayofstrings -join ", "
$joinedstring
은 Item1, Item2, Item3