Sign in to follow this  
Followers 0
danpaul23

_IEPropertyGet question

3 posts in this topic

I'm more or less completely new to this and have been trying to understand the code below which Dale was kind enough to provide me with. I understand most of what it is doing, or at least I think I do. I downloaded the IE Dom explorer and I see how the program is basically looking for tables with certain class names and then looking for tables with certain class names within those until it arrives at the right level, so to speak. It then uses the _IEPropertyGet function to pull the desired information.

Now, what I'm confused about is how you can get the information that _IEPropertyGet "pulls" and use that to make some sort of decision.

The way I would think I should do this would be to create a variable and then use that variable in a formula to make a decision.

the way I was trying to get the is as follows:

$oVar = _IEPropertyGet($oSpan, "innertext")

I'm probably doing something really basic and wrong but, I assumed that _IEPropertyGet($oSpan, "innertext") would give me the same value as a variable as it would output through ConsoleWrite. But, it doesn't.

Again, thanks for the help. Looking forward to the day when I'll be able to do the same.

CODE
#include <IE.au3>

$sURL = "http://www.amazon.com/s/ref=nb_ss_b/102-5993488-0177751?url=search-alias%3Dstripbooks&field-keywords=mystery&Go.x=0&Go.y=0&Go=Go"

$tryAttach = True

$oIE = _IECreate($sURL, $tryAttach)

$oTables = _IETableGetCollection($oIE)

For $oTable in $oTables

If String($oTable.className) = "searchresults" Then

$oTDs = _IETagnameGetCollection($oTable, "td")

For $oTD in $oTDs

If String($oTD.className) = "searchitem" Then

$oSpans = _IETagNameGetCollection($oTD, "span")

For $oSpan in $oSpans

Switch String($oSpan.className)

Case "srTitle"

ConsoleWrite("Title: " & _IEPropertyGet($oSpan, "innertext") & @CR)

Case "listprice"

ConsoleWrite("ListPrice: " & _IEPropertyGet($oSpan, "innertext") & @CR)

Case "saleprice"

ConsoleWrite("SalePrice: " & _IEPropertyGet($oSpan, "innertext") & @CR)

Case "sr_price"

ConsoleWrite("SRPrice: " & _IEPropertyGet($oSpan, "innertext") & @CR)

Case "otherprice"

ConsoleWrite("OtherPrice: " & _IEPropertyGet($oSpan, "innertext") & @CR)

EndSwitch

Next

ConsoleWrite("--------------------------------------------" & @CR)

EndIf

Next

EndIf

Next

Share this post


Link to post
Share on other sites



The way I would think I should do this would be to create a variable and then use that variable in a formula to make a decision.

the way I was trying to get the is as follows:

$oVar = _IEPropertyGet($oSpan, "innertext")

I'm probably doing something really basic and wrong but, I assumed that _IEPropertyGet($oSpan, "innertext") would give me the same value as a variable as it would output through ConsoleWrite. But, it doesn't.

It certainly should. You'll need to show your code.

One common issue is that if there is no text returned (perhaps there is only HTML inside a particular SPAN), then the function will return a numeric 0 when you might expect a null (""). Because AutoIt uses variants instead of typed variables, this numeric can cause you trouble (note, that is why you see the String function in the example). As an example, if you use a comparison like this: If _IEPropertyGet($oSpan, "innertext") = "Some String" Then... if the innertext is null, it returns 0, this forces a numeric comparison with "Some String", this causes "Some String" to get converted to a numeric before the comparison, any string converted to a numeric is 0, and as you know 0=0 is True.

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

It certainly should. You'll need to show your code.

One common issue is that if there is no text returned (perhaps there is only HTML inside a particular SPAN), then the function will return a numeric 0 when you might expect a null (""). Because AutoIt uses variants instead of typed variables, this numeric can cause you trouble (note, that is why you see the String function in the example). As an example, if you use a comparison like this: If _IEPropertyGet($oSpan, "innertext") = "Some String" Then... if the innertext is null, it returns 0, this forces a numeric comparison with "Some String", this causes "Some String" to get converted to a numeric before the comparison, any string converted to a numeric is 0, and as you know 0=0 is True.

Dale

Yes, that is what is happening. The variable is showing as a zero when I try to present it in something like a MsgBox.

i.e. if I put this in the code you provide:

CODE
Switch String($oSpan.className)

Case "srTitle"

MsgBox(0, "Example", _IEPropertyGet($oSpan, "innertext"))

Or, if I create a variable of the the span first and display that variable, I get the same thing. The Msg box(s) will show "zero".

I'm not sure if there is only html in the span but I assumed since it was outputing text or numbers in the ConsoleWrite, it would do the same in the message box. I'll look into this more.

Thanks again.

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