Retrieve two last lines of read html page (PowerShell and VBS)

Hi all.
I'd like to write a script which is kind of obvious for scriptiong experts but now for me :) The key is:

Let's assume you have a webpage http://intranet/logs.html. Page is static, although ERROR or SUCCESS are changing depending on some action name. So it looks like:
<td><img src="ok.jpg" /></td>
<td><font size="2" color="red">TEMP</font></td>

Unfortunately the name is in the second line. I need to check if TEMP item has ok.jpg or bad.jpg lamp. So what I need to do is:

Get-Web http://intranet/logs.html
and then find a string TEMP and check if line before has ok.jpg or bad.jpg.

Need to do it in VBS also. Any scripts appretiated, points will be spread evenly :)
LVL 2
Rem-8Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yehudahaCommented:
you need a vbs file to check the line before the last line

<td><img src="ok.jpg" /></td>

if understand i don't need to retrive 2 line only the line i wrote above.
and then what print to the screen ?
0
x-menIT super heroCommented:
get-whatever | select-string TEMP -Context 1,0
0
x-menIT super heroCommented:
(new-object net.webclient).DownloadString("http://intranet/logs.html") | select-string TEMP -Context 1,0
0
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

jostranderCommented:
If I understood the question... this VBS should work :)
'---------------------------------------------
'	User Variables
'---------------------------------------------
strURL="http://intranet/logs.html"

'String to search for
strSearch="TEMP"

'---------------------------------------------

strText=WebGet(strURL)

strImage=GetImage(strText,strSearch)

msgbox strImage




Function WebGet(myURL)

	Set http = CreateObject("MSXML2.xmlhttp")
	http.open "GET",myURL,FALSE
	http.send ""
	
	WebGet=http.responseText
	
End Function



Function GetImage(myText,mySearch)
	ON ERROR RESUME NEXT
	
	arrText=split(myText,vbCrLf)
	
	for i = 0 to ubound(arrText)
		line=arrText(i)
		If instr(line,mySearch) then
			lastLine=arrText(i-1)
			Set objRegEx = New RegExp
			objRegEx.Pattern = "[a-z0-9\._-]+.jpg"
			objRegEx.IgnoreCase=True
			Set colMatches=objRegEx.Execute(lastLine)
			GetImage=colMatches.Item(0)
			Exit Function
		End If
	next
End Function

Open in new window

0
jostranderCommented:
And powershell...
# ---------------------------------------------
#	User Variables
# ---------------------------------------------

$strURL="http://intranet/logs.html"


# String to search for
$strSearch="TEMP"


# ---------------------------------------------

$req = New-Object -COMObject "MSXML2.ServerXMLHTTP.6.0"
$req.Open("GET", $strURL)
$req.Send()
$text = $req.responsetext

$arrText=$text.split("`n")

for ($i=0; $i -le $arrText.getupperbound(0); $i++) {
	$line=$arrText[$i]
	if ($line.contains($strSearch)) {
		$lastLine= $arrText[$i-1]
		$pattern = "[a-z0-9\._-]+.jpg"
		$matches = [regex]::Matches($lastLine,$pattern)
		$matches[0].value
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rem-8Author Commented:
I needed to change regex to second "contains" and worked fine. Thanks!
0
jostranderCommented:
Cool, glad I could help.  What was your final expression pattern?
0
Rem-8Author Commented:
# ---------------------------------------------
#      User Variables
# ---------------------------------------------

$strURL="http://intanet/logs.html"


# String to search for
$strSearch="Test"
$strok="uparrow.gif"


# ---------------------------------------------

$req = New-Object -COMObject "MSXML2.ServerXMLHTTP.6.0"
$req.Open("GET", $strURL)
$req.Send()
$text = $req.responsetext

$arrText=$text.split("`n")

for ($i=0; $i -le $arrText.getupperbound(0); $i++) {
      $line=$arrText[$i]
      if ($line.contains($strSearch)) {
                      echo "Found line" . $line
            $lastLine = $arrText[$i-1]
                      echo $lastLine
            if ($lastLine.contains($strok)) {
                               echo "Server UP"
                      }
      }
}

Had to echo some debug comments as you see :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.