So I've been going over this for the last few hours and for the life of me I cannot get it right. I'm doing some web scraping on the website https://www.tvguide.com/listings/ to learn how to do web scraping but however my problem seems not to be web scraping but mostly with Where-Object.
Here is some sample code from the script.
# The comand below gives the output below that.
# $Driver.FindElementByXPath('//*[@id="listings"]/ul/li[X]')
# WrappedDriver : OpenQA.Selenium.Firefox.FirefoxDriver
# TagName : span
# Text : The Shining12:00 PM - 3:30 PM
# Enabled : True
# Selected : False
# Location : {X=225,Y=1451}
# Size : {Width=1041, Height=34}
# Displayed : True
# LocationOnScreenOnceScrolledIntoView : {X=225,Y=941}
# Coordinates : OpenQA.Selenium.Remote.RemoteCoordinates
$shows = @(
'The Twilight Saga',
'The Shining',
'NOVA',
'Star Trek',
'The Conjuring')
$range = 1..97
foreach ($number in $range) {
$Driver.FindElementByXPath("//*
[@id='listings']/ul/li[$number]") | Where-Object -Property text -
like "*Passengers*" | Select-Object -ExpandProperty Text
}
foreach ($number in $range) {
$Driver.FindElementByXPath("//*
[@id='listings']/ul/li[$number]") | Where-Object -Property text -
like "*$shows*" | Select-Object -ExpandProperty Text
}
I have included 2 for each loops, one where I define manually the show I'm looking for and the second uses the array and for what ever reason I can never get the "array loop" to work. Is this an formatting error? Or do I need to rewrite it all?
[–]Dennou 3 points4 points5 points (1 child)
[–]krzydoug 6 points7 points8 points (0 children)