Sign in to follow this  
Followers 0
litlmike

IE Grab this value

5 posts in this topic

Trying to grab data from a webpage that is not in a table.

For example let us use:

http://dictionary.reference.com/browse/information

I would like to grab that red text on the page that reads (pronunciation):

"[in-fer-mey-shuhn]"

I would like to do this in a manner where I can carry this over to any word on Dictionary.com and grab the pronunciation.

I don't really have any useful code, but here is where I started, but of course, it doesn't give me the info I need.

#include <IE.au3>

$sUrl = "http://dictionary.reference.com/browse/information"
$oIE = _IECreate($sUrl, 1)

$oTables1 = _IETableGetCollection($oIE, 0)
$aArray1 = _IETableWriteToArray($oTables1)

For $i = 0 to Ubound($aArray1, 2) - 1
    ConsoleWrite($aArray1[0][$i] & "              " & $aArray1[1][$i] & @CR)
Next

Share this post


Link to post
Share on other sites



I think I am getting a little bit closer with the code, but I don't know how to refine it to only display the needed info.

#include <IE.au3>

#Region --- IE-Builder generated code Start ---
$sUrl = "http://dictionary.reference.com/browse/information"
$oIE = _IECreate($sUrl, 1)

$oElements = _IETagNameAllGetCollection ($oIE)
For $oElement In $oElements
    If $oElement.Tagname = "SPAN" Then
        MsgBox(0, "Element Info", "Tagname: " & $oElement.tagname & @CR & "innerText: " & $oElement.innerText)
    EndIf
Next

Share this post


Link to post
Share on other sites

The element you want is the second SPAN element with a classname of "pron"

Try this:

#include <IE.au3>

#Region --- IE-Builder generated code Start ---
$sUrl = "http://dictionary.reference.com/browse/information"
$oIE = _IECreate($sUrl, 1, 1,1, 0)

$oElements = _IETagNameGetCollection ($oIE, "SPAN")
Local $i = 0
For $oElement In $oElements
    If String($oElement.classname) = "pron" Then
        $i += 1
        If $i = 2 Then
            ConsoleWrite("--> outerHTML: " & $oElement.outerHTML & @CR & @CR & "--> innerText: " & $oElement.innerText & @CR)
            ExitLoop
        EndIf
    EndIf
Next

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

The element you want is the second SPAN element with a classname of "pron"

Try this:

Dale

Thanks a lot Dale! I would not have thought to use String () and .InnerText, those are both a bit foreign to me. I was goofing around a bit with ClassName, but without String() it didn't matter.

Thanks a ton for your help!

Share this post


Link to post
Share on other sites

Thanks a lot Dale! I would not have thought to use String () and .InnerText, those are both a bit foreign to me. I was goofing around a bit with ClassName, but without String() it didn't matter.

Thanks a ton for your help!

String() is important because the COM interface returns a numeric 0 if the .className value is not specified. Without String() you end up evaluating: Is 0 = "pron"? AutoIt looks at the left side of the equals sign, sees a numeric and converts the right side to numeric in order to do the comparison... a string converted to numeric is always 0, so you get a surprising match of your If condition.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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
Sign in to follow this  
Followers 0