Jump to content

Recommended Posts

Posted (edited)

Hello, all!

I am using _IEGetObjByID to pull out some data. However, the ID is always changing from item to item. Is there a way that I can include a wildcard of sorts? Here is an example of the HTML I am using

<SPAN id=listPricePV4167itna231 class=pnaPV4167itna pnaType="listPrice">Call</SPAN>
<SPAN id=listPricePP9374itna253 class=pnaPP9374itna pnaType="listPrice">Call</SPAN>
<SPAN id=listPriceQQ0435itna451 class=pnaQQ0435itna pnaType="listPrice">Call</SPAN>

I am using _IEGetObjByID (or trying to) to get the id...the three digit number after "itna" is what is killing me. Any ideas?

The code I am using so far is below. I thought I had found a pattern, but then the numbers just began to be random.

$x = 0
        For $i = 1 to UBound($aArray) -1
                $itemid = StringStripWS($aArray[$i][0],8)
                ;MsgBox(64,"$msrp test",$msrp)
                If $x = 0 Then
                    $price = "listPrice"&$itemid&"itna"
                    Else
                    $price = "listPrice"&$itemid&"itna"&$x
                EndIf
                $prices = _IEGetObjById($oIE,$prices)
;~              MsgBox(64,"test",$prices)
;~              MsgBox(64,"$prices test",_IEPropertyGet($prices,"innertext"))
                    $aArray[$i][2] = _IEPropertyGet($prices,"innertext")
                    $count = $count + 1
                    $x=$x + 11
;~                  $i = $i + 1
;~              Else
;~              EndIf

                Next

Thanks!

Edit--

Oops, forgot to select HTML as the type of code for box 2 and 3...

Edited by allSystemsGo
Posted (edited)

You can use my signature with one of these xpaths:

$xpath = "//span[contains(@class,'pna') And contains(@class,'itna')]"
$xpath = "//span[contains(@id,'listPrice') And contains(@id,'itna')]"

Grabs an array of all dom objects matching the above xpath

Func BGe_IEGetDOMObjByXPathWithAttributes($oIEObject, $sXPath, $iMaxWait=Default, $bCreateObjCol=Default) ; Get dom object by XPath

First param is $oie, or can be any IE Object...second param is the xpath to search, relative to the $oIEObject.

You can then loop through the array, and proceed with the object you expect.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

The returns are objects, so it will appear to be blank, but you can use them like any return of the _ie functions...any of the IE properties/methods, etc (to use the properties, you must move the object to a temp variable, since it's not syntactically correct to do $aReturn[0].innertext as an example).

I'm using arrays, because I couldn't figure out how to create 'collections'

As long as the return is an array, there are matches in it.  The bounds of the array are the matches based on the xpath.

If the return is $aReturn, then do this to click the first object:

_IEAction($aReturn[0],"Click")

Simple example:

$oIE = _IEAttach("Match an ever")
$aReturns = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//link")
For $i = 0 To UBound($aReturns)-1
    $var = $aReturns[$i]
    ConsoleWrite("Link=[" & $i + 1 & "]...href=[" & $var.href & "]." & @CRLF )
Next
ConsoleWrite(@CRLF)
$aReturns = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//link[contains(@href,'ipbv')]")
For $i = 0 To UBound($aReturns)-1
    $var = $aReturns[$i]
    ConsoleWrite("Link=[" & $i + 1 & "]...href=[" & $var.href & "]." & @CRLF )
Next

Output at my run time:

Link=[1]...href=[http://www.autoitscript.com/forum/favicon.ico].
Link=[2]...href=[http://www.autoitscript.com/forum/public/style_images/master/meta_image_autoit.png].
Link=[3]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/autoit_custom.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[4]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/calendar_select.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[5]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_styles.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[6]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_common.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[7]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_ckeditor.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[8]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/prettify.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[9]...href=['?do=embed' frameborder='0' data-embedContent>>
Link=[10]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_print.css].
Link=[11]...href=[http://www.autoitscript.com/forum/forum/2-general-help-and-support/].
Link=[12]...href=[http://www.autoitscript.com/forum/user/77857-allsystemsgo/].
Link=[13]...href=[http://www.autoitscript.com/forum/rss/forums/4-announcements-and-site-news/].
Link=[14]...href=[http://www.autoitscript.com/forum/rss/forums/8-autoit-v3-general-help-and-support/].
Link=[15]...href=[http://www.autoitscript.com/forum/rss/forums/9-autoit-v3-developer-chat/].
Link=[16]...href=[http://www.autoitscript.com/forum/rss/downloads/].
Link=[17]...href=[http://aut1.autoit-cdn.com/forum/public/js/3rd_party/ckeditor/skins/ips/editor.css?t=67f5d04ffba93d6b1d60bb7b446f0467].

Link=[1]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/autoit_custom.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[2]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/calendar_select.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[3]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_styles.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[4]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_common.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[5]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/css_11/ipb_ckeditor.css?ipbv=5dd9fe056830304d510b22280b5507bb].
Link=[6]...href=[http://aut1.autoit-cdn.com/forum/public/style_css/prettify.css?ipbv=5dd9fe056830304d510b22280b5507bb].

Hey, cool, you can go directly off the array:

$oIE = _IEAttach("Match an ever")
$aReturns = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//link")
For $i = 0 To UBound($aReturns)-1
    
    ConsoleWrite("Link=[" & $i + 1 & "]...href=[" & $aReturns[$i].href & "]." & @CRLF )
Next
ConsoleWrite(@CRLF)
$aReturns = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//link[contains(@href,'ipbv')]")
For $i = 0 To UBound($aReturns)-1
    ConsoleWrite("Link=[" & $i + 1 & "]...href=[" & $aReturns[$i].href & "]." & @CRLF )
Next
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

This creates an array smaller than the one that I am going to insert the data into therefore I get this error...

C:\Users\allSystemsGo\Desktop\AutoIT_Script\ingrammicrodata.au3 (197) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$list = $bArray[$i].innertext
$list = ^ ERROR
Posted (edited)

I'd need the code to see why.  Either your xpath is too confining, and you are not getting all the objects you expect, or you're not logically looping within the bounds of the array.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

Just needed to change some code around...this has me goin

$count = 1
        $xpath = "//span[contains(@id,'listPrice') And contains(@id,'itna')]"
        $bArray=BGe_IEGetDOMObjByXPathWithAttributes($oIE,$xpath)
        For $i = 1 to UBound($bArray) -1
            $list = $bArray[$i].innertext
;~          MsgBox(64,"test",$list)
                    $aArray[$i][2] = $list
                    $count = $count + 1
                Next

Great tool! Thanks for your help

Posted

This simpler way should work

#Include <Array.au3>

; $html = _IEDocReadHTML($oIE)
$html = '<SPAN id=listPricePV4167itna231 class=pnaPV4167itna pnaType="listPrice">Call</SPAN>' & @crlf & _
'<SPAN id=listPricePP9374itna253 class=pnaPP9374itna pnaType="listPrice">Call</SPAN>' & @crlf & _
'<SPAN id=listPriceQQ0435itna451 class=pnaQQ0435itna pnaType="listPrice">Call</SPAN>'

$res = StringRegExp($html, '(?i)id=(listprice\w+)', 3)
;_ArrayDisplay($res)
$txt = ""
For $i = 0 to UBound($res)-1
    $ids = _IEGetObjById($oIE, $res[$i])
    $txt &= _IEPropertyGet($ids,"innertext") & @crlf
Next
Msgbox(0,"", $txt)
Posted

 

This simpler way should work

#Include <Array.au3>

; $html = _IEDocReadHTML($oIE)
$html = '<SPAN id=listPricePV4167itna231 class=pnaPV4167itna pnaType="listPrice">Call</SPAN>' & @crlf & _
'<SPAN id=listPricePP9374itna253 class=pnaPP9374itna pnaType="listPrice">Call</SPAN>' & @crlf & _
'<SPAN id=listPriceQQ0435itna451 class=pnaQQ0435itna pnaType="listPrice">Call</SPAN>'

$res = StringRegExp($html, '(?i)id=(listprice\w+)', 3)
;_ArrayDisplay($res)
$txt = ""
For $i = 0 to UBound($res)-1
    $ids = _IEGetObjById($oIE, $res[$i])
    $txt &= _IEPropertyGet($ids,"innertext") & @crlf
Next
Msgbox(0,"", $txt)

Yeah, this works pretty great, too! Thanks!

Posted (edited)

Which RegExp could I use to get

<SPAN id=pricePX9503itna56 pnaType="price">$293.16</SPAN>

and differentiate from

<SPAN onclick="javascript: try{populateDiscountInfoDIV(this,'PX9503','0','','0',null,'MD','41-379516','false');&#13;&#10;&#9;&#9;&#9;&#9;    hideDiscountDivFrompopupFlag=false;&#13;&#10;&#9;&#9;&#9;&#9;   return false;}catch(e){}" onmouseover="javascript:try{ browserName(event,'View Discount Details',0,this);discountTipFix();}catch(e){}" onmouseout="javascript: try{browserName(event,'View Discount Details',1,this);}catch(e){}" id=priceLnkPX9503itna56 style="CURSOR: pointer; TEXT-DECORATION: underline">

So far I can find both, but I only want id=pricePX9503itna56

Edited by allSystemsGo
Posted (edited)

Hopefully no attributes are added prior to the id, or you will need to adjust the regexp for that also.  That's why I prefer using dom objects...be it XML or HTML, since it will always find exactly what you want, regardless of the other data, spacing, etc

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

This would probably be best, for the regexp route...take any number of chars (prior to closing the >)

$res = StringRegExp($html, '(?i)SPAN[^>]*id=(listprice\w+)', 3)

Continue to look throught he SPAN until you find an 'id'...if not found prior to the close of the span.*>, then skip to next

There could still be issues with spacing between the id and = and value...also, could be issues with ' or "...maybe?

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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
×
×
  • Create New...