Sign in to follow this  
Followers 0
Sovereign

IE Get class collection?

3 posts in this topic

I am currently running a bot that runs multiple instances of IE and nagivates through pages. The problem I am having is the CPU usage pegs to 100% while its running, all of it devoted to iexplore.exe. What bugs me the most though is the fact that IE crashes usually every 10-15min but can randomly last an hour or so. I think this may be caused by overloading IE with for loops.

Here is a piece of the program. On average the Tag collection contains 500 or so items which may be overloading IE. Is there any way to get a collection of objects with a specific class? I have tried $oIE.document.GetElementsByClassName("map-link") and it said it wasn't an object.

$hfind = _IETagNameGetCollection ($oIE, "A")
    
    For $h in $hfind
        if String($h.className) = "map-link" Then
            if stringinstr($h.href,"/mip/") and stringinstr($h.href,"map?lid=") Then 
                _IENavigate($oIE,$h.href,0)
                _IELoadWait ($oIE,500,15000)
                exitloop
            endif
        endif
    Next

Does calling .href or .classname use IE resources or is it done independently in my program?

Share this post


Link to post
Share on other sites



Are you sure the document.GetElementsByClassName() method even exists in your version of IE? It has a little asterisk that says "New for IE9" on the linked page.

Your script makes a call to the COM interface of IE to get those properties, and IE does the processing of the DOM to answer. I wouldn't expect a loop of 500 elements to "overload" anything. It's not usually that fragile.

You could try a Sleep(10) in the loop to see if that makes any difference. That would add a worst-case 500loops X 10ms = 5sec to the processing time while testing it.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Are you sure the document.GetElementsByClassName() method even exists in your version of IE? It has a little asterisk that says "New for IE9" on the linked page.

Your script makes a call to the COM interface of IE to get those properties, and IE does the processing of the DOM to answer. I wouldn't expect a loop of 500 elements to "overload" anything. It's not usually that fragile.

You could try a Sleep(10) in the loop to see if that makes any difference. That would add a worst-case 500loops X 10ms = 5sec to the processing time while testing it.

:graduated:

No I'm not sure that it exists I had just seen it somewhere and tried to use it. Is there any other methods for IE7 or IE8 that allow me to grab objects based off of the class? I added sleep(1) to the loop and it still ran perfect but it seemed to crash just as quick. Maybe I'll try it again with 10 milliseconds. At first I thought my program was having errors but then I realized IE just decided to crash randomly and it caused my bot to crash in the process. I've tried to close the IE windows every so often so the memory usage doesn't go over 250mb. I'm not sure why it needs to use that much memory but it will slowly build up to around 2gb if I don't close it. This didn't seem to help at all though.

This problem occurs on IE7, IE8, and IE9 on different computers. Can you take a look at this code and let me know if you see anything that IE might not like. A lot of the code is kind of redundant because I was trying to pinpoint where the errors where coming from.

$oIE = _IECreate("",0,1,1,0)
_IELoadWait ($oIE,500,15000)
$START = int($CmdLine[1])
$STOP = int($CmdLine[2])

Func CitySearch($pName,$pAddress)
    _IENavigate($oIE,"http://newyork.citysearch.com/",0)
    _IELoadWait ($oIE,500,15000)
    $oForm = _IEFormGetObjByName ($oIE, "searchForm")
    if stringinstr(_IEPropertyGet($oForm,"outerhtml"),'what') > 0 and stringinstr(_IEPropertyGet($oForm,"outerhtml"),'where') > 0 Then
        $Query1 = _IEFormElementGetObjByName ($oForm, "what")
        _IEFormElementSetValue ($Query1, $pName)
        $Query2 = _IEFormElementGetObjByName ($oForm, "where")
        _IEFormElementSetValue ($Query2, $pAddress)
        _IEFormSubmit ($oForm,0)
        _IELoadWait ($oIE,500,15000)
    EndIf

    $hfind = _IETagNameGetCollection ($oIE, "a")
    if $hfind <> 0 Then
    For $h in $hfind
    sleep(1)
    if stringinstr(_IEPropertyGet($h, "outerhtml"),"name=") > 0 and stringinstr(_IEPropertyGet($h, "outerhtml"),"href=") > 0 Then   
        if String($h.Name) = "search_grid.results.1.title" Then
            if stringinstr($h.href,"/profile/") Then 
                _IENavigate($oIE,$h.href,0)
                _IELoadWait ($oIE,500,15000)
                exitloop
            endif
        endif
    endif
    Next
    EndIf

    $hfind = _IETagNameGetCollection ($oIE, "span")
    if $hfind <> 0 Then
    For $h in $hfind
    sleep(1)
    if stringinstr(_IEPropertyGet($h, "outerhtml"),"class=") > 0 Then
        if String( $h.className) = "street-address" and stringinstr($pAddress,StringLeft($h.innertext,5)) and String($h.innertext) <> "0"  Then 
            $addressbar = _IEPropertyGet($oIE, "locationurl")
            if stringinstr($addressbar,"/profile/") > 0 Then
                $split = stringsplit($addressbar,"/", 1)
                for $s = 0 to UBound($split)-1 step 1
                    if $split[$s] = "profile" Then return "http://www.citysearch.com/profile/" & $split[$s+1]
                Next
                
            
            endif
        endif
    endif
    Next
    endif
    return "0"
EndFunc

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