Jump to content

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


7121
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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