Jump to content

Victoria's Secret website java too slow for script >_<


Recommended Posts

I missed a clearance sale the other day so i thought i'd write a script that polls the vs clearance section and notify me when new items / changes pop up on clearance... as i got deeper into it i figured i'd track what items were available (colors in the dropdown boxes etc) however it seems that the site loads too slowly for autoit to see all the fields... especially when you select a color in the dropdown box and wait for the java to return 'in-stock' or 'only a few left' status messages... :idea:

is there a more logical way to slow down and wait than hard coding sleep(###) all over the place?

my debug script so far:

#include <Constants.au3>
#include <IE.au3>
#include <GuiConstants.au3>
#include <Array.au3>
#Include <date.au3>
#include <file.au3>

; Global $oIE = _IECreate("",0,0,0)

Global $oIE = _IECreate()

Local $CategoryArray[25]

$CategoryArray[0] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_V=M&ProductTypes=V&rfnbr=1&page=all"
$CategoryArray[1] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_J=M+++&ProductTypes=J&rfnbr=1&page=all"
$CategoryArray[2] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_F=M&ProductTypes=F&rfnbr=1&page=all"
$CategoryArray[3] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_Q=M+++&ProductTypes=Q&rfnbr=1&page=all"
$CategoryArray[4] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_C=OS++&ProductTypes=C&rfnbr=1&page=all"
$CategoryArray[5] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_I=M+++&ProductTypes=I&rfnbr=1&page=all"
$CategoryArray[6] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_B=32B&ProductTypes=B&rfnbr=1&page=all"
$CategoryArray[7] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_P=M&ProductTypes=P&rfnbr=1&page=all"
$CategoryArray[8] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_L=M&ProductTypes=L&rfnbr=1&page=all"
$CategoryArray[9] = "http://www2.victoriassecret.com/Sale/search_results.cfm?ProductTypes=D&&rfnbr=1&Size_D=8/M&page=all"
$CategoryArray[10] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_T=M&ProductTypes=T&rfnbr=1&page=all"
$CategoryArray[11] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_Z=M&ProductTypes=Z&rfnbr=1&page=all"
$CategoryArray[12] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_G=M&ProductTypes=G&rfnbr=1&page=all"
$CategoryArray[13] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_M=8%2FM&ProductTypes=M&rfnbr=1&page=all"
$CategoryArray[14] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_N=8%2FM&ProductTypes=N&rfnbr=1&page=all"
$CategoryArray[15] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_O=8%2FM&ProductTypes=O&rfnbr=1&page=all"
$CategoryArray[16] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_Y=8%2FM&ProductTypes=Y&rfnbr=1&page=all"
$CategoryArray[17] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_K=8%2FM&ProductTypes=K&rfnbr=1&page=all"
$CategoryArray[18] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_E=8%2FM&ProductTypes=E&rfnbr=1&page=all"
$CategoryArray[19] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_A=8%2FM&ProductTypes=A&rfnbr=1&page=all"
$CategoryArray[20] = "http://www2.victoriassecret.com/Sale/select_size.cfm?Prod_Type=R&rfnbr=1&page=all"
$CategoryArray[21] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_S=9&ProductTypes=S&rfnbr=1&page=all"
$CategoryArray[22] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_W=34B&ProductTypes=W&rfnbr=1&page=all"
$CategoryArray[23] = "http://www2.victoriassecret.com/Sale/search_results.cfm?Size_W=8%2FM&ProductTypes=W&rfnbr=1&page=all"
$CategoryArray[24] = "http://www2.victoriassecret.com/Sale/select_size.cfm?Prod_Type=U&rfnbr=1&page=all"

for $i = 0 to UBound($CategoryArray) - 1
    ConsoleWrite("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CR)
    ConsoleWrite("Testing $CategoryArray: " & $i & " '" & $CategoryArray[$i] & "'" & @CR)
    _CategoryParse($CategoryArray[$i])
Next


; get list....
Func _CategoryParse($URL)

    ;go to url
    _IENavigate($oIE, $URL)
    ; _IELoadWait($oIE)
    
    
    $oDIVs = _IETagNameGetCollection($oIE, "div")
        ; loop through and see if class is coll2-right (each of those is a thumbnail)
        For $oDIV in $oDIVs
#cs
<DIV class=coll2-right>
    <A href="/commerce/Sale/onlineProductDisplay.vs?namespace=productDisplay&amp;origin=onlineProductDisplay.jsp&amp;event=display&amp;prnbr=GV-239520&amp;size=M&amp;rfnbr=1">
        <IMG height=189 alt="" src="/images/tmblg4/V285521_S47.jpg" width=140 border=0 name=TMBLG4_239520></A> 
    <H2>
    <P>
    <A href="/commerce/Sale/onlineProductDisplay.vs?namespace=productDisplay&amp;origin=onlineProductDisplay.jsp&amp;event=display&amp;prnbr=GV-239520&amp;size=M&amp;rfnbr=1">
        Embroidered strapless Bra Top dress<BR>
        <SPAN class=grey>More Colors</SPAN>
            <BR>Orig. $88<BR>
        <SPAN style="COLOR: #cc0000">Clearance $54.99</SPAN></A> 
    </P>
    </H2>
</DIV>
#ce
            ; Need to search URL for Product ID...
            ; capture IMG thumbnail location / data
            ; <P> has Item Name Orig and Clearance Price...
            ; inside <P> first <SPAN> inside <BR> has orig price
            ; inside <P> second <SPAN> clearance price
            
            ; root for url's is http://www2.victoriassecret.com
            
            if StringInStr($oDIV.className, "coll2-right") Then
                $oHREFs = _IETagNameGetCollection($oDIV, "A")
                for $oHREF in $oHREFs
                    
                    ConsoleWrite("ItemURL: " & $oHREF.href & @CR)
                    _DetailsPage($oHREF.href)

                    
                    ; now try to get the item id via regex...
                    ;Option 2, single return, php/preg_match() style
                    $array = StringRegExp($oHREF.href, 'prnbr=(.*?)&', 2)
                    ; for $i = 0 to UBound($array) - 1
                    ;   ConsoleWrite("RegExp Test with Option 2 - " & $i & "'" & $array[$i] & "'" & @CR)
                    ; Next
                    
                    ConsoleWrite ("Item ID: " & $array[1] & @CR)
                    
                    ExitLoop
                Next
                
                $oIMGs = _IETagNameGetCollection($oDIV, "IMG")
                for $oIMG in $oIMGs
                    ConsoleWrite("ItemIMG: " & $oIMG.src & @CR)
                    ExitLoop
                Next
            EndIf
        Next            
EndFunc

Func _DetailsPage($DetailsURL)
    $oIE_Details = _IECreate($DetailsURL, 0, 0, 0)
    
    ; $oIE_Details = _IECreate($DetailsURL)
    
    ;go to url
    ; _IENavigate($oIE_Details, $DetailsURL)
    ; _IELoadWait($oIE_Details)
    
    ; <div class="scott_alt0"> Main Item
    ;   <div class="headings"> Item Name
    ;   <p class="txt"> Item Description (First Link) Additional Details / Prices in Second Link EX:
    ;   <p class="txt"><!-- mp_trans_disable_start -->21" from waist. GV-237-325 <br>Orig. $118. 
    ;       <span style='color:#cc0000;'>Clearance $39.99.</span><!-- mp_trans_disable_end --></p>

    
    ; <div class="scott_alt"> Additional Items (matching pants etc)
    
    ; Dropdown boxes aren't contained in a div #@^#$^#@ so unable to determine if its linked to main or alt object...
    $scott_droplist_flag = 0
    
    $oDIVs = _IETagNameGetCollection($oIE_Details, "div")

            for $oDIV in $oDIVs
                ; ConsoleWrite("Found oDIVs: " & $oDIV.className & @CR)
                
                if StringInStr($oDIV.className, "scott_alt0") Then ; now we have the main item....
                    ; Now going to try to JUST get the div's underneath the main item
                    ; ConsoleWrite("Found scott_alt0" & @CR)
                    $oDIV_SUBs = _IETagNameGetCollection($oDIV, "div")
                    for $oDIV_SUB in $oDIV_SUBs
                        ; ConsoleWrite("Article 1 DEBUG $oDIV_SUB: " & $oDIV_SUB.innerText & @CR)
                        if StringInStr($oDIV_SUB.className, "headings") Then
                            ; Clothing Title Name...
                            ConsoleWrite("Article 1 Item Name: " & $oDIV_SUB.innerText & @CR)
                        EndIf
                    Next
                    
                    $oPs = _IETagNameGetCollection($oDIV, "p")
                    for $oP in $oPs
                        if StringInStr($oP.className, "txt") Then
                            ; First time its the description second is the prices...
                            if StringInStr($oP.innerText, "Clearance") Then
                                ConsoleWrite("Article 1 Item Price: " & $oP.innerText & @CR)
                                ; now try to get the item bs via regex...
                                $OrigPriceArray = StringRegExp($oP.innerText, 'Orig. \$(.*)\.', 2)
                                if @error = 0 Then
                                    ConsoleWrite ("Article 1 Orig. Price: " & $OrigPriceArray[1] & @CR)
                                Else
                                    ConsoleWrite ("WARNING Orig. Price REGEX FAILED: Trying Again...." & @CR)
                                    $OrigPriceArray = StringRegExp($oP.innerText, 'Orig \$(.*?)\.', 2)
                                    if @error = 0 Then
                                        ConsoleWrite ("Article 1 Orig. Price: " & $OrigPriceArray[1] & @CR)
                                    Else
                                        $OrigPriceArray = StringRegExp($oP.innerText, 'Orig\. (.*?)\.\r', 2)
                                        if @error = 0 Then
                                            ConsoleWrite ("Article 1 Orig. Price: " & $OrigPriceArray[1] & @CR)
                                        Else
                                            ConsoleWrite ("WARNING Orig. Price REGEX FAILED AGAIN: " & $oP.innerText & @CR)
                                            MsgBox(0, "REGEX FAILED", "REGEX FAILED")
                                        EndIf
                                    EndIf
                                EndIf
                                $ClearancePriceArray = StringRegExp($oP.innerText, 'Clearance \$(.*)\.', 2)
                                ConsoleWrite ("Article 1 Clearance Price: " & $ClearancePriceArray[1] & @CR & @CR)
                            Else
                                ConsoleWrite("Article 1 Item Desc: " & $oP.innerText & @CR)
                            EndIf
                        EndIf
                    Next
                    
                EndIf
                
                if StringCompare($oDIV.className, "scott_alt") = 0 Then
                    ; this is the second article of clothing.... 
                    
                    $oPs = _IETagNameGetCollection($oDIV, "p")
                    for $oP in $oPs
                        ; ConsoleWrite("Article 2 DEBUG p: " & $oP.innerText & @CR)
                        ; ConsoleWrite("Article 2 DEBUG p: " & $oP.innerHTML & @CR)
                        if StringInStr($oP.innerHTML, "Type11B") Then
                            ; Clothing Title Name...
                            ConsoleWrite("Article 2 Item Name: " & $oP.innerText & @CR)
                        EndIf
                        
                        if StringInStr($oP.className, "txt") Then
                            ; First time its the description second is the prices...
                            if StringInStr($oP.innerText, "Clearance") Then
                                ConsoleWrite("Article 2 Item Price: " & $oP.innerText & @CR)
                                ; now try to get the item bs via regex...
                                $OrigPriceArray = StringRegExp($oP.innerText, 'Orig. \$(.*)\.', 2)
                                if @error = 0 Then
                                    ConsoleWrite ("Article 2 Orig. Price: " & $OrigPriceArray[1] & @CR)
                                Else
                                    ConsoleWrite ("WARNING Orig. Price REGEX FAILED: Trying Again...." & @CR)
                                    $OrigPriceArray = StringRegExp($oP.innerText, 'Orig \$(.*?)\.', 2)
                                    if @error = 0 Then
                                        ConsoleWrite ("Article 2 Orig. Price: " & $OrigPriceArray[1] & @CR)
                                    Else
                                        $OrigPriceArray = StringRegExp($oP.innerText, 'Orig\. (.*?)\.\r', 2)
                                        if @error = 0 Then
                                            ConsoleWrite ("Article 2 Orig. Price: " & $OrigPriceArray[1] & @CR)
                                        Else
                                            ConsoleWrite ("WARNING Orig. Price REGEX FAILED AGAIN: " & $oP.innerText & @CR)
                                            MsgBox(0, "REGEX FAILED", "REGEX FAILED")
                                        EndIf
                                    EndIf
                                EndIf
                                $ClearancePriceArray = StringRegExp($oP.innerText, 'Clearance \$(.*)\.', 2)
                                ConsoleWrite ("Article 2 Clearance Price: " & $ClearancePriceArray[1] & @CR)
                            Else
                                ConsoleWrite("Article 2 Item Desc: " & $oP.innerText & @CR)
                            EndIf
                        EndIf
                    Next
                EndIf
                
                if StringInStr($oDIV.className, "scott_droplist") Then
                        ; ConsoleWrite("$oDIV.className = result_title innerText = " & $oDIV.innerHTML & @CR)
                    
                        $oSelects = _IETagNameGetCollection($oDIV, "select")
                        for $oSelect in $oSelects
                            ; ConsoleWrite("Selects inner text: " & $oSelect.innerText & @CR)
                        
                            if StringInStr($oSelect.className, "sel-color") Then
                        
                                $oOptions = _IETagNameGetCollection($oSelect, "option")
                    
                                for $oOption in $oOptions
                                    ; HERE is where we have the values of the drop down boxes....
                                    If $scott_droplist_flag = 0 then 
                                        ConsoleWrite("Article 1 DropDown Box Values: " & $oOption.innerText & @CR)
                                    Else
                                        ConsoleWrite("Article 2 DropDown Box Values: " & $oOption.innerText & @CR)
                                    EndIf
                            
                                    ; NOW SELECT SOMETHING TO SEE IF THAT MSG INFO POPS UP.....
                                    $oForm = _IEFormGetObjByName ($oIE_Details, "form")
                                    ; $oBox = _IEFormElementGetObjByName ($oForm, "select")
                                    _IEFormElementOptionselect ($oSelect, $oOption.innerText, 1, "byText")
                                    
                                    ; sleep to make sure we get returned values? >.<
                                        Sleep(500)
                                
                                    ; Now that crap has been selected... check for pop up values:
                                    ; note may need a sleep or some delay?
                                    $oResultsDiv = _IEGetObjById($oIE_Details, "atp-msg-0")
                                    $oDIV_DISPLAYs = _IETagNameGetCollection($oResultsDiv, "span")

                                    for $oDIV_DISPLAY in $oDIV_DISPLAYs
                                        ; ConsoleWrite("Found oDIVs: " & $oDIV.className & @CR)
                                        if StringInStr($oDIV_DISPLAY.className, "atp-msg-cntnr") Then
                                            If $scott_droplist_flag = 0 then
                                                ConsoleWrite("Article 1 Availibility status: " & $oDIV_DISPLAY.innerText & @CR)
                                            Else
                                                ConsoleWrite("Article 2 Availibility status: " & $oDIV_DISPLAY.innerText & @CR)
                                            EndIf
                                        EndIf
                                    Next
                            
                                Next
                                $scott_droplist_flag =  1 ; Assuming loop gets here again it will be options for the second item...
                            EndIf
                        Next
                EndIf
                
                ; now to check availability.... DEBUG... this might happen twice when you have two items in one view???
                ; if so it needs to be nestled >_< just verified it needs to be nested... #@!#!
                
                
            Next
                    
    
    _IEQuit($oIE_Details)
EndFunc

example output it worked here:

Testing $CategoryArray: 0 'http://www2.victoriassecret.com/Sale/search_results.cfm?Size_V=M&ProductTypes=V&rfnbr=1&page=all'

ItemURL: http://www2.victoriassecret.com/commerce/Sale/onlineProductDisplay.vs?namespace=productDisplay&origin=onlineProductDisplay.jsp&event=display&prnbr=GW-262905&size=M&rfnbr=1

Article 1 Item Name:

Victoria's Secret Pink™

Article 1 Item Name:

Graffiti-print sliding triangle top

Article 1 Item Desc: Say it with sparkle. Pick your top and bottom sizes separately.

• Diamanté trim

• Removable padding

• Ties at neck and back

• Fully lined

• Imported nylon/spandex; lining: polyester/spandex

Article 1 Item Price: GW-262-905 Orig. $28.50. Clearance $16.99.

Article 1 Orig. Price: 28.50. Clearance $16.99

Article 1 Clearance Price: 16.99

Article 1 DropDown Box Values: color

Article 1 Availibility status: 0

Article 1 DropDown Box Values: black grafitti

Article 1 Availibility status: In-stock. Just a few left

Article 1 DropDown Box Values: white grafitti

Article 1 Availibility status: In-stock

Article 2 Item Name: Graffiti-print string bottom

Article 2 Item Desc: Say it with sparkle. Pick your top and bottom sizes separately.

however on multiple runs the same output can totally miss the second value in the dropdown box (which is wierd since thats hardcoded in the source) and of course its eh availabilty status java popup:

Article 1 DropDown Box Values: color

Article 1 Availibility status: 0

Article 1 DropDown Box Values: black grafitti

Article 1 Availibility status: In-stock. Just a few left

Article 1 DropDown Box Values: 0

Article 1 Availibility status: In-stock. Just a few left

Article 2 Item Name: Graffiti-print string bottom

Article 2 Item Desc: Say it with sparkle. Pick your top and bottom sizes separately.

Don't let that status fool you, I am no advanced memeber!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...