Jump to content

How can I get a list of all the div id tags in a webpage?


Recommended Posts

I want to retrieve all the div id's in an IE window, count them and list them. I want this in an array. I have tried several of the _IE functions with no luck. I seem to be getting stuck on getting the window handle of the IE window.

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

Local $oIE = _IECreate("www.youtube.com")
Sleep(5000)
$aArray = _IETagNameGetCollection ($oIE, "div")

MsgBox(0,0,$oIE)
_ArrayDisplay($aArray)

The MsgBox doesn't even show up so I imaging thats why the array also doesn't show. What am I missing?

 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Looks like you're confusing object/string and collection/array
Please try this

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

Local $oIE = _IECreate("www.autoit.fr")
Sleep(3000)
$oDivs = _IETagNameGetCollection ($oIE, "div")

Local $res
For $oDiv In $oDivs
   If $oDiv.id <> "" Then $res &= $oDiv.id & @crlf
Next
 MsgBox(0,"", $res)

$aArray = StringSplit($res, @crlf, 3)
_ArrayDisplay($aArray)

 

Link to comment
Share on other sites

The above lists all the div id's on the page. It does not list any nested DIV's. Can you breakdown what the line:

   If $oDiv.id <> "" Then $res &= $oDiv.id & @crlf

I dont fully understand what is happening.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...