I am trying to write a script that downloads web sites information. I am able to download the information but I cannot seem to get the filtering working. I have an a series of values that I want skipped stored in $TakeOut
but it does not recognize the values in the if -eq $TakeOut
. I have to write a line for each value.
What I am wondering is, if there is a way to use a $value
as over time there will be a considerable amount of values to skip.
This works but is not practical in the long run.
if ($R.innerText -eq "Home") {Continue}
Something like this would be preferable.
if ($R.innerText -eq $TakeOut) {Continue}
Here is a sample of my code.
#List of values to skip
$TakeOut = @()
$TakeOut = (
"Help",
"Home",
"News",
"Sports",
"Terms of use",
"Travel",
"Video",
"Weather"
)
#Retrieve website information
$Results = ((Invoke-WebRequest -Uri "https://www.msn.com/en-ca/").Links)
#Filter and format to new table of values
$objects = @()
foreach($R in $Results) {
if ($R.innerText -eq $TakeOut) {Continue}
$objects += New-Object -Type PSObject -Prop @{'InnerText'= $R.InnerText;'href'=$R.href;'Title'=$R.href.split('/')[4]}
}
#output to file
$objects | ConvertTo-HTML -As Table -Fragment | Out-String >> $list_F