7121 Posted August 24, 2013 Share Posted August 24, 2013 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 More sharing options...
JohnOne Posted August 24, 2013 Share Posted August 24, 2013 Identify the first one, set a counter variable and increment it from that point until it is 5. Collect your data. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
7121 Posted August 24, 2013 Author Share Posted August 24, 2013 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? Link to comment Share on other sites More sharing options...
kylomas Posted August 24, 2013 Share Posted August 24, 2013 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 More sharing options...
7121 Posted August 24, 2013 Author Share Posted August 24, 2013 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: expandcollapse popup;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 More sharing options...
Moderators Melba23 Posted August 24, 2013 Moderators Share Posted August 24, 2013 7121, a program to collect music from HypeM.com by downloading the cacheFrom 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts