T
T
TechNOIR2017-03-04 16:49:01
PowerShell
TechNOIR, 2017-03-04 16:49:01

Powershell. How to append information to a file?

Good day!
I am using the Export-Excel module. I'm trying to unload through foreach on several links values ​​into a table. But in the end, only one row gets into the table - the values ​​​​from the last link in the file. Out-File has something like -Append, which appends to a file. Maybe this is how it should be here?

[Reflection.Assembly]::LoadFrom("C:\selenium\net40\WebDriver.dll")
$url = Get-Content D:\dww.txt
$ie = New-Object OpenQA.Selenium.PhantomJS.PhantomJSDriver
foreach ($u in $url) {
$ie.Navigate().GoToUrl($u)
$title = $ie.FindElementByXPath("//h1[contains(@class, 'fullstory')]")
$fullstory = $ie.FindElementByClassName("comment")
$tracklist = $ie.FindElementByXPath("//*[contains(@id,'news-id')]")
$links = $ie.FindElementByXPath("//*[contains(@class, 'link')]")
$img = $ie.FindElementsByclassname("stars").findelementbytagname("img").getattribute("src")
 
$h = Write-Output Стиль,Формат,"Год выпуска",Размер,"Название альбома",Исполнитель,Треклист,Ссылка,Обложка
$data = ($fullstory.text).split("`n") -replace ": ","=" | Where {$_.Trim()} | Out-String | ConvertFrom-StringData | Foreach {[pscustomobject]$_} | Select $h
$data.Ссылка = $links.text
$data.Треклист = $tracklist.text
$data.Обложка = $img
$data | Export-Excel d:\filedark2.xlsx -AutoSize
Write-Host $u " - выгружено"
}
$ie.Quit()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2017-03-04
@azarij

maybe it will be easier for everyone if you use one of these services?
www.hongkiat.com/blog/web-scraping-tools

D
Denis, 2017-03-06
@denilenko

Form a multidimensional array with the necessary data in a loop, and only then, in one line, insert it into Excel (look again at the code that I sent you in your last question).
By the way, this will be almost an order of magnitude faster than accessing Excel in a loop at each iteration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question