Followers 0

# Copy Links from 3 Pages and Put them into an Array

## 2 posts in this topic

Hi All,

Im just having trouble working out how to grab the links from 3 seperate webpages (these are IPP printer install links generated by a Novell server), dump them all into the one array for sorting purposes and then reoutput this to a new html file which will then be uploaded to a website.

The code I have currently will open the 3 pages and retrieve the links using the IELinkGetCollection() function, perform a StringInStr command to make sure its a printer link and then output that to a HTML document (i think ive done this part wrong i want it to actually write the source html to a file but at the moment for testing it shows it in a browser window which is kinda cool). The problem is it does it seperately for each of the 3 pages so the final (single page) html output is in this order: Page 1 Printers > Page 2 Printers > Page 3 Printers whereas if possible i would like all the links melded into one logical unit (im thinking array) so i can sort them, and then hopefully later on i would like to do some sort of Function or logic in the script to output the printers link (by using the naming standard of the printer) to various sections on the webpage (i.e for printers that reside on level 4 go to a Level 4 section etc).

Basicall these are the couple of things i would like help with:

* How do I get my 3 IELinkGetCollection() variables into one array or section where i can sort them (alphabetical order using the \$oLink.outerText value of each printer) and if any1 has any ideas on what would be the best way to then pass this array to some form of logic (a Select statement looks like what im after but not sure??) that will check for a part of the naming standard and then output this printer to a particular part of the HTML code).

* I think i misunderstood the _IEDocWriteHTML function in that i thought it wrote to a .htm file but it seems to write it directly to an open browser. Is there any easy way to write the html structure i have at the moment to a .htm file or will i have to do a FileWriteLine to each of the \$shtml lines??

* And if some1 could explain where the \$oLink var came from and what it does (not the \$oLinksx one's) i didn't set this anywhere (it was in some of the examples so i used it) and i have no idea where it came from ?? Im guessing one of the include things??

Phew.. i think thats it for now guys. I will post my current code below as well as attach a copy of the webpage that has the structure of the links on it. Any and all help is appreciated and if there is anything drastic or terrible about the code ive written please don't hesitate to correct it... its the only way i'll learn lol

Thanks Heaps!

#include <IE.au3>
#include <Array.au3>

;the following 4 vars set up the IE windows that contain the printer IPP addresses (3 are hidden, 1 is not)
\$oIE1 = _IECreate ("http://192.168.125.119/ipp/pdisplay.htm", 0, 0, 1, -1)
\$oIE2 = _IECreate ("http://192.168.125.120/ipp/pdisplay.htm", 0, 0, 1, -1)
\$oIE3 = _IECreate ("http://192.168.125.121/ipp/pdisplay.htm", 0, 0, 1, -1)
\$oIE4 = _IECreate()

;these 3 vars should collect all the links that are on each of the printer pages
\$oLinks1 = _IELinkGetCollection(\$oIE1)
\$oLinks2 = _IELinkGetCollection(\$oIE2)
\$oLinks3 = _IELinkGetCollection(\$oIE3)

;just a varaible that will be used to count how many links were found matching my StringInStr search parameter
\$installLinks = 0

;a variable that will be used in the alternating of the background row colour
\$bgvar = 0

;sets the initial background colour
\$bgcolour = "EFEEE9"

;??? not sure if i need these but ive left them in for the moment
Dim \$ippLinks[1]
\$ippLinks[0] = "placeholder"
Dim \$ippNames[1]
\$ippNames[0] = "placeholder"

;sets up the basic HTML content that will be used written to the webpage
\$sHTML = ''
\$sHTML &= '<HTML>' & @CRLF
\$sHTML &= '<HEAD>' & @CRLF
\$sHTML &= '<TITLE>Test Page With the Printers</TITLE>' & @CRLF
\$sHTML &= '</HEAD>' & @CRLF
\$sHTML &= '<BODY>' & @CRLF
\$sHTML &= '<H1>McKell Printers</H1>' & @CRLF
\$sHTML &= '<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0 SCROLL="yes">' & @CRLF
\$sHTML &= '<TBODY>' & @CRLF

;creates a for that checks each thingy in \$oLinks1 if it matches the stringinstr function then adds it to the html content
For \$oLink In \$oLink1 ;??? i dont know where this \$oLink var came from lol i didnt set it anywhere
If StringInStr(\$oLink.href, "http://192.168.125.119/ippdocs/isinstf.htm?ippPrinterURL=") Then ;the \$oLink.href means what the link actually contains
\$installLinks = \$installLinks + 1 ;increments the \$installLinks counter for informational purposes
_ArrayAdd(\$ippLinks, \$oLink.href) ;??? not sure if what i am doing is right here
tablerowBGchange() ;runs the function which should alternate the bgcolour var for each link that is written to the html
;the sexy part of the code that adds a new table row to the html page for each printer found along with the \$oLink.outerText value (which is the printer name) and a link to click to install the printer (\$oLink.outerText)
\$sHTML &= '<TR bgColor=#' & \$bgcolour & '><TD width="50%"><A href="' & \$oLink.href & '">' & \$oLink.outerText & '</A></TD></TR>' & @CRLF
EndIf
Next
;check above comments pretty much the same for this loop
For \$oLink In \$oLinks2
If StringInStr(\$oLink.href, "http://192.168.125.120/ippdocs/isinstf.htm?ippPrinterURL=") Then
\$installLinks = \$installLinks + 1
_ArrayAdd(\$ippLinks, \$oLink.href)
tablerowBGchange()
\$sHTML &= '<TR bgColor=#' & \$bgcolour & '><TD width="50%"><A href="' & \$oLink.href & '">' & \$oLink.outerText & '</A></TD></TR>' & @CRLF
EndIf
Next
;check above comments pretty much the same for this loop
For \$oLink In \$oLinks3
If StringInStr(\$oLink.href, "http://192.168.125.121/ippdocs/isinstf.htm?ippPrinterURL=") Then
\$installLinks = \$installLinks + 1
_ArrayAdd(\$ippLinks, \$oLink.href)
tablerowBGchange()
\$sHTML &= '<TR bgColor=#' & \$bgcolour & '><TD width="50%"><A href="' & \$oLink.href & '">' & \$oLink.outerText & '</A></TD></TR>' & @CRLF
EndIf
Next

;closes the IE object things
_IEQuit(\$oIE1)
_IEQuit(\$oIE2)
_IEQuit(\$oIE3)

;just displays how many links were found
MsgBox(48, "Number of Links Found", "The Number of Links Found matching the StringInStr is: " & \$installLinks)

;the closing html
\$sHTML &= "</TBODY>" & @CRLF
\$sHTML &= "</TABLE>" & @CRLF
\$sHTML &= "</BODY>" & @CRLF
\$sHTML &= "</HTML>"

;??? this writes html code but i think i misunderstood this command in that it writes it directly to the open browser, i gotta figure out how to save it to a htm file, may have to do it as FileWriteLine along with the rest of it?
_IEDocWriteHTML (\$oIE4, \$sHTML)
_IEAction (\$oIE4, "refresh")

;function to change the background row colour
Func tablerowBGchange()
If \$bgvar = 0 Then
\$bgcolour = "EFEEE9"
\$bgvar = 1
Else
\$bgcolour = "FFFFFF"
\$bgvar = 0
EndIf
EndFunc

pdisplay.htm

#### Share this post

##### Share on other sites

* I think i misunderstood the _IEDocWriteHTML function in that i thought it wrote to a .htm file but it seems to write it directly to an open browser. Is there any easy way to write the html structure i have at the moment to a .htm file or will i have to do a FileWriteLine to each of the \$shtml lines??

ok i think ive figured out this part... if i add the following code

\$file = FileOpen("c:\testweb.htm", 2)
FileWrite(\$file, \$sHTML)

it seems to write the source file fine as when using the _IEDocWriteHTML command.

however im still stumped with the array stuff...

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now
Followers 0