Jump to content
Sign in to follow this  
7121

Getting the nth object during the For...In Loop

Recommended Posts

7121

Making a macro where it fetches data from a website.

Product name and product id are about 5 objects away from each other.

$products = _IETagNameAllGetCollection($ieObject)
For $product In $products
      $id = product.id
      $name = product.innertext - 5 ;<= this is where i'm having the problem
Next 

Basically i want to get the object innertext that is 5 objects away from the object id.

How can one proceed this?

Share this post


Link to post
Share on other sites
7121

hmmm, i know this is NOT brilliant of me but how can one set a counter variable for something that is happening before instead of after?

I guess you can say, perhaps a sample?

Share this post


Link to post
Share on other sites
kylomas

7121,

This is what J1 is suggesting...

$products = _IETagNameAllGetCollection($ieObject)
Local $cnt = 0
For $product In $products
    $id = product.id
    $cnt += 1
    If $cnt = 5 Then $name = product.innertext
Next

However, there is probably a better solution if you give us the URL you are working with.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
7121

well if you really must know, it's actually a program to collect music from HypeM.com by downloading the cache. I didn't want to put the whole thing up because it might be viewed as bad ethics.

But it's not like i'm hacking it or anything, i'm just using the cache that pops on my computer, i consider it the same as taking the time to record the song for my own personal use.

Anyway here's the script:
 

;Remove Temporary Internet Files
_RemoveLeftovers()


;Create IE Window
$ieObject = _IECreate("about:blank", 0, 1, 1, 0)
WinWait(WinGetHandle($ieObject))


;Go to URL given
TraySetToolTip("navigating")
_IENavigate($ieObject, $links[1][1], 1)
If @error Then
_ErrorMsg("Problem loading " & $links[1][1], 1)
EndIf
Sleep(3000)
;fetch objects for ids
TraySetToolTip("Fetching objects to ids")
$playIDs = _IETagNameAllGetCollection($ieObject)
For $playID In $playIDs
If StringRegExp($playID.id, "play_ctrl_.+") Then
$artist = $playID.innertext - 5
MsgBox( 0, "", $artist)
Exit
;click the song
_IEAction($playID, "click")
$timer1 = TimerInit()
TraySetToolTip("Fetching the cache")
Do
;fetch the cache
_FetchCache()
;check folder if file exists
$timer2 = TimerInit()
Do
Sleep(150)
Until DirGetSize($dataPath, 2) > 0 Or TimerDiff($timer2) > 5000
If TimerDiff($timer1) > 60000 Then _ErrorMsg("Could not fetch the cache", 1)
Until DirGetSize($dataPath, 2)
;locate the cache in the data folder
$file = _RecFileListToArray($dataPath, "*", 1, 0, 0, 2)
TraySetToolTip("Fetching song from cache")
;wait for file to exist
Do
Sleep(150)
Until UBound($file) <> 0
;if there are two files, you got a problem =/
If $file[0] > 1 Then _ErrorMsg("There appears to be more than 1 song found", 1)
;read the fetched cache file
TraySetToolTip("reading extracted cache file")
$songURL = FileRead($file[1])
$songURL = StringReplace($songURL, "\", "")
$songURL = StringRegExp($songURL, 'url":"(.*?)"}', 1)
TraySetToolTip("Downloading: " & $artist & " - " & $track)
InetGet($songURL[0], $downloadPath & $artist & " - " & $track & ".mp3")
If @error Then
;MsgBox(4096, "HypeMoon Download Error - "&$id2&"|"&$artist&" - "&$track, $mp3_string)
EndIf
FileWrite(@ScriptDir & "\log.txt", $playID.id & ";")
_RemoveLeftovers()
EndIf
Next

 

Share this post


Link to post
Share on other sites
Melba23

7121,

 

a program to collect music from HypeM.com by downloading the cache

From the HypeM.com Terms of Use:

5. SITE CONTENT. Subscriber may preview audio Content and other items displayed on the Site for personal use only. Subscriber shall not download or store audio Content from the Site.

So it is not "bad ethics", it is illegal. Thread locked. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×