Jump to content
RickB75

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

Recommended Posts

RickB75

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

Share this post


Link to post
Share on other sites
dragan

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

Share this post


Link to post
Share on other sites
RickB75

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.

Share this post


Link to post
Share on other sites
dragan

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

Share this post


Link to post
Share on other sites
RickB75

Thank you soooo much for that info. This is really gonna help me out. I owe you!

Share this post


Link to post
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

  • Similar Content

    • ur
      By ur
      Is there any UDF to remove all anchor tags <a> with a particular class (and also its sub elements completely) in a html document.
      Here the classes are browse and breadcrumbs
      Like in the below image.


       
      I am not able to find that option in IE.au3
       
      Please suggest.
    • milkmoron
      By milkmoron
      I am trying to automate something in a web browser but i need some help with finding the html code to a web applet. How do I access the code.
    • Seminko
      By Seminko
      Is there a way to grab non-hardcoded but rather javascript generated data from a webpage?
      Tried a get request as well as _IEBodyReadHTML but both seem to grab the code without the javascript generated data.
      $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "link", False) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status Global $DataArray[10][5] If $oStatusCode <> 200 Then Exit MsgBox(1, "Error", "Status Code <> 200") EndIf FileWrite(@ScriptDir & "\output.txt", $oReceived) ; //////// #include <IE.au3> Local $FullLink = "link" Local $oIE = _IECreate($FullLink, 0, 0) _IELoadWait($oIE) Local $sText = _IEBodyReadHTML($oIE) FileWrite(@ScriptDir & "\output.txt", $sText)  
    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

    • Burgs
      By Burgs
      Hello,
        I have a website with a Google Map I setup using the Google Map API.  It works and displays just fine.  However to make it useful to me I need to be able to dynamically change the map to display different areas by sending new Latitude and Longitude coordinates.  I am having difficulty making this happen.  Here is my code thus far:
      #include <IE.au3> $oIE3 = _IECreate("http://my_sample_website.html") ;just an example, not an actual site... _IELoadWait($oIE3) $s_word = "lat:" $oInputs = _IETagNameAllGetCollection($oIE3) if @error <> 0 Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error is: " & @error) EndIf ;@error For $oInput In $oInputs if Number($iPos) == -1 Then $iPos = StringInStr($oInput.innerHTML, String($s_word)) if (Number($iPos) > 0) AND (@error == 0) Then ConsoleWrite("I FOUND IT...! " & String($s_word) & @CRLF) $sHTML = _IEBodyReadHTML($oIE3) $_lat_look = 0 $_lng_look = 0 $_end_look = 0 ;default $_lat_look = StringInStr(String($sHTML), "lat:") if Number($_lat_look) <> 0 Then $_lng_look = StringInStr(String($sHTML), "lng:") if Number($_lng_look) <> 0 Then $_end_look = StringInStr(String($sHTML), "}") if Number($_end_look) <> 0 Then ConsoleWrite("HTML BODY: " & $sHTML & @CRLF) $_old_lat = String(StringMid(String($sHTML), $_lat_look, ($_lng_look - $_lat_look))) $_old_lng = String(StringMid(String($sHTML), $_lng_look, ($_end_look - $_lng_look))) ConsoleWrite("$_old_lat: " & $_old_lat & @CRLF) ConsoleWrite("$_old_lng: " & $_old_lng & @CRLF) $_new_lat = "lat: " & String("-34.397") & ", " $_new_lng = "lng: " & String("150.644") & "}; " ConsoleWrite("...new lat is: " & String($_new_lat) & " new lng is: " & String($_new_lng) & @CRLF) $_LOOK = StringReplace($_old_lat, 1, String($_new_lat)) $_LOOK2 = StringReplace($_old_lng, 1, String($_new_lng)) ConsoleWrite("$_LOOK: " & $_LOOK & "$_LOOK2: " & $_LOOK2 & @CRLF) EndIf ;'$_end_look' NOT "0"... $iPos = -1 EndIf ;'String($s_word)' was found in the collection '$oInputs' EndIf ;'$iPos' is "-1" Next  
        I am having trouble trying to replace the line in the HTML ($sHTML variable in my example) that contains the "lat:" and "lng:" information.  I figure if I can replace that line everything else remains the same, and in theory, the map should cycle to display a map with the new latitude and longitude coordinates...I hope. 
        I have attempted to write the $sHTML to a text document and then use '_IEBodyWriteHTML' to read it back into the webpage HTML however that is not working.  There must be an easier method to accomplish this...what am I missing here...?  Any thoughts greatly appreciated.  Regards.       
×