Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Web Page Webpage Element Explorer Scrape Scraper Scraping
;*************************************************************************** ;** Webpage Element Explorer ;** ;** Purpose: Discovering form elements on a webpage ;** Inputs: ignorehidden, inputonly ;** Outputs: Highlights each form element using a red solid border ;** and Display attribute information in a Box ;** Reference: ;** ;** ;** Developer: Deana Falk 2013.10.24 ;*************************************************************************** #DefineFunction udfIEPageLoadWait( objIE ) ; Wait for webpage to load While !(objIE.readyState == 'complete' || objIE.readyState == 4 ) TimeDelay(0.1) EndWhile While !(objIE.document.readyState == 'complete' || objIE.document.readyState == 4 ) TimeDelay(0.1) EndWhile Return 1 #EndFunction ; Modify these values to change how the script operates ignorehidden = @TRUE ; change to @FALSE to query hidden form elements inputonly = @FALSE ; change to @TRUE to query only INPUT form elements. boxcoords = '750,0,1000,200' ; coordinates of the display box. boxclr = '255,0,0' ; box background color url = "https://techsupt.winbatch.com/techsupt/sampleform.html" ; Display form element data in a box title = 'Discovering form elements on a webpage' BoxesUp(boxcoords, @NORMAL) BoxDrawRect(1,'0,0,1000,1000',2) BoxColor(1,boxclr,0) BoxCaption(1, title) WindowOnTop(title, 1) ; Initialize MSIE object oIE = ObjectCreate("InternetExplorer.Application") oIE.Visible = @TRUE ; Change to @FALSE to hide the process from the user oIE.Navigate(url) ; Wait for webpage to load udfIEPageLoadWait( oIE ) ;*************************************************************************** ; Get Colection of Forms ;*************************************************************************** ; Get document object oDoc = oIE.Document ; Forms Collection oForms = oDoc.Forms ; OR ; getElementsByTagName Method ;oForms = oDoc.getElementsByTagName("FORM") formlist = "" ; Initialize variable If oDoc != 0 ; Check if you have a valid document handle ; Loop through the collection of forms using index count = oForms.Length For index = 0 To count-1 oForm = oForms.Item(index) If ObjectTypeGet(oForm)=="EMPTY" Then Continue formlist = formlist:@TAB:index:"|":oForm.id:"|":oForm.name Next ; ALTERNATE WAY: Loop through the collection of forms ;index = 0 ;ForEach oForm in oForms ; If ObjectTypeGet(oForm)=="EMPTY" then continue ; formlist = formlist:@tab:index:"|":oForm.id:"|":oForm.name ; index = index+1 ;Next Else Pause('Notice','Unable to obtain a handle to the document object on this webpage. Check URL.') EndIf formlist = StrTrim(formlist) ; remove leading tab selection = "" If formlist != "" While selection == "" selection = AskItemlist("Select Form Index on a webpage", formlist, @TAB, @UNSORTED, @SINGLE ) EndWhile formindex = Int(ItemExtract(1,selection,"|")) oForm = oForms.Item(formindex) ;Pause('Form Object Handle ', oForm) Else Pause('Notice','There are no forms on this page!') EndIf ;*************************************************************************** ; Get Collection of Elements in the Form ;*************************************************************************** If oForm != 0 ; Check if you have a valid form handle cElements = oForm.Elements elementindex = 0 BoxButtonDraw(1, 1, 'Next Element', '250,750,650,900') ForEach oElement In cElements ; Get element attributes ; Alternatice option: oElement.getAttribute("attributename") tag = oElement.nodeName ;The value of tagName is the same as that of nodeName. type = StrUpper(oElement.Type) id = oElement.Id name = oElement.Name value = oElement.Value ; Check if user wants to ignore HIDDEN form elements If ignorehidden If StrUpper(type) == 'HIDDEN' Then Continue EndIf ; Check if user wants to see non INPUT form elements If inputonly If StrUpper(tag) != 'INPUT' Then Continue EndIf ; Highlight each element on the form oElement.style.border = "1mm solid red" ; Set focus on element If !oElement.disabled ErrorMode(@OFF) oElement.Focus() ErrorMode(@CANCEL) EndIf ; Display results BoxDrawText(1, "0,0,1000,1000",'Element Index: ' : elementindex : @LF :'Tag: ' : tag : @LF : 'Type: ' : type : @LF :'Id: ' : id : @LF :'Name: ' : name : @LF :'Value: ': value, @TRUE, 0 ) While !BoxButtonStat(1, 1) TimeDelay(0.5) EndWhile ; Remove element highlight oElement.style.border = "" ; Increment element counter elementindex = elementindex+1 Next Else Pause('Notice','Unable to obtain a handle to a form on this webpage. Check URL and formnumber.') EndIf :CleanUp ; Quit oIE.Quit ; Close open COM/OLE handles oElement oDoc = 0 oIE = 0 Exit
Article ID: W18124
Filename: !! Webpage Element Explorer !!.txt
File Created: 2019:08:14:09:27:28
Last Updated: 2019:08:14:09:27:28