Jump to content
computergroove

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

Recommended Posts

computergroove

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

Share this post


Link to post
Share on other sites
mikell

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)

 

Share this post


Link to post
Share on other sites
computergroove

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

Share this post


Link to post
Share on other sites
mikell

Same way but using $oDiv.classname

Share this post


Link to post
Share on other sites
computergroove

Where can I find the tags like .classname or .id and others? Where can I find more info on understanding how autoit teanslates "For $oDiv To $oDivs".


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

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.