Help with tags in COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AllUrBaseRBelong2Us
Posts: 35
Joined: 09 Nov 2015, 11:15

Help with tags in COM

23 Nov 2015, 04:57

Hey there,
I'm writing a script to retrieve info from a tag which looks like this

Code: Select all

<div class="some class name" style="background-image:insert random url here"></div>
I'm trying to extract style name/ backgroundimage URL.

So, is there any way to extract that info?

Just a FYI: I've tried storing the classnames in a var using getElementsbyClassName and looped through them but they don't show all the class names - the one I need isn't there. I've checked with Inspect Element in IE and can confirm that the specific class name DOES exist. That's why I'm trying to meddle with the style properties now.

Thanks in advance for your help.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Help with tags in COM

23 Nov 2015, 05:13

You just have to parse the DOM for div elements

Code: Select all

html =
(
<html><head></head>
<body>
<div class="a class name">foo</div>
<div class="some class name" style="background-image:insert random url here">This is what I'm after</div>
<div class="another class name">bar</div>
</body></html>
)

document := ComObjCreate( "htmlfile" ), document.Write( html )

try While ( divObj := document.getElementsByTagName( "div" )[ a_index-1 ] )
{
    if ( divObj.className = "some class name" )
        Value := divObj.innerText
}

msgbox % Value
obviously change the objects etc back ie.document... and so on.
AllUrBaseRBelong2Us
Posts: 35
Joined: 09 Nov 2015, 11:15

Re: Help with tags in COM

23 Nov 2015, 05:16

TLM wrote:You just have to parse the DOM for div elements

Code: Select all

html =
(
<html><head></head>
<body>
<div class="a class name">foo</div>
<div class="some class name" style="background-image:insert random url here">This is what I'm after</div>
<div class="another class name">bar</div>
</body></html>
)

document := ComObjCreate( "htmlfile" ), document.Write( html )

try While ( divObj := document.getElementsByTagName( "div" )[ a_index-1 ] )
{
    if ( divObj.className = "some class name" )
        Value := divObj.innerText
}

msgbox % Value
obviously change the objects etc back ie.document... and so on.
Sorry but I didn't get what you meant by that. Do I have to download the website's HTML code to a var and then proceed?
AllUrBaseRBelong2Us
Posts: 35
Joined: 09 Nov 2015, 11:15

Re: Help with tags in COM

23 Nov 2015, 07:02

@TLM, thanks for being so helpful on IRC :D The script runs brilliantly. I've found out where I was making a mistake
I wrote

Code: Select all

divObj.backgroundimage
instead of

Code: Select all

divObj.style.backgroundimage

Thanks a ton!

PS:You're the best! Have a great day :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], peter_ahk and 366 guests