Jump to content

how can I get a certain class object inside of a <Div> Tag


Recommended Posts

Can you guys help me with this. I'm sure it's simple but I'm still pretty green with Autoit. I can grab the innerHTML from the Div tag and the links that I need but, I need the "data-vin" as an identifier. Basically something like this, If my script sees this object "data vin" then get the inner text of the object (the vin #) and the next link below it.  Here's what I've got so far and a link to my website.

 

As always, any help is greatly appreciated!

If you view source, look at line # 1535

#include <IE.au3>

Local $oIE = _IECreate("http://www.beamantoyota.com/new-inventory/index.htm")

;Get collection of elements tagged "LI" for List Item
 $oListItems = _IETagNameGetCollection ($oIE, "LI")


    
    For $oListItem In $oListItems

        $odivs = $oListItem.getElementsByTagName("div")

        For $odiv in $odivs
            $text = $odiv.class
            ConsoleWrite("Div (text): " & $text & @CRLF)

            ;Get all the elements tagged "a" for Anchor
            ;This needs an error handler in case the list item
            ;  doesn't have any anchors
            $oAnchors = $oListItem.getElementsByTagName("a")
            
            For $oAnchor In $oAnchors
              ;Get the href of each anchor
              $sHref = $oAnchor.href

                ConsoleWrite("    Link Info: " & $sHref & @CRLF)
                
            Next
        
        Next

    
    Next
Link to comment
Share on other sites

You would need to use the command:

$odiv.getAttribute("data-vin")

as in:
 

#include <IE.au3>
ConsoleWrite('!--------- STARTING ----------' & @CRLF)
Local $oIE = _IECreate("http://www.beamantoyota.com/new-inventory/index.htm")
Local $oListItems = _IETagNameGetCollection ($oIE, "LI")
For $oListItem In $oListItems
    Local $odivs = _IETagNameGetCollection($oListItem, 'div')
    For $odiv in $odivs
        Local $dataVin = $odiv.getAttribute("data-vin")
        If $dataVin <> '' Then
            ConsoleWrite('+ Found it, data-vin: ' & $dataVin & @CRLF)
            Local $oAnchors = _IETagNameGetCollection($odiv, 'a')
            For $oAnchor in $oAnchors
                Local $sHref = $oAnchor.href
                ConsoleWrite(">    Link Info: " & $sHref & @CRLF)
            Next
            ConsoleWrite('----------------------------' & @CRLF)
        EndIf
    Next
Next
ConsoleWrite('!--------- ENDING ----------' & @CRLF)
_IEQuit($oIE)

but you would have to be specific about which URL from 'a'-elements you want to extract.

EDIT: Also, if you find the DIV you want, you should use _IETagNameGetCollection related to that div as object when searching for "a"-elements inside that div.
 

Edited by dragan
Link to comment
Share on other sites

Dragan,

        That works great. I will go and trim / omit the additional links. I have  a question. That command you gave (".getattribute"). Where can I find a list of them? That would help out soooo much. I did try using the .classname = "data-vin" and I was getting a true or false returned.

Link to comment
Share on other sites

The reason I know this is because I had the same question:

The list is quite long, you'll need to know what you're doing in order to get the right parameter. You can find all commands here: http://msdn.microsoft.com/en-us/library/ie/hh772960%28v=vs.85%29.aspx. GetAttribute is under section Methods (direct link here).

If you go to the "DIV" element, you'll see which types of members does it contain, and you'll see that under "Methods" it really does support "getattribute".

Edited by dragan
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...