Jump to content

Check if Link is Unique


Recommended Posts

If a link appears more than once, I want to skip one of the occurences. In this example it will display 2 occurences of the same link, because the same link appears twice on the page. I would like to skip one of those occurrences.

TIA

#include <IE.au3>

$s_Url = "http://www.youtube.com/results?search_query=Miss+Teen+USA+South+Carolina&search=Search"
$sVid = "http://www.youtube.com/watch?v="
$oIE = _IECreate ($s_Url,1)
$oLinks = _IELinkGetCollection ($oIE)

For $oLink In $oLinks
        
    If StringInStr ($oLink.href, $sVid) Then
        MsgBox (0, "", $oLink.href, 1)
    EndIf
Next
Link to comment
Share on other sites

Can someone tell me why the first script here works, but not the second script? The second script seems to just jump to the end and never evaluates the last 3 lines.

#include <IE.au3>
#include <Array.au3>

$s_Url = "http://www.youtube.com/results?search_query=Miss+Teen+USA+South+Carolina&search=Search"
$sVid = "http://www.youtube.com/watch?v="
$oIE = _IECreate ($s_Url,1)
$oLinks = _IELinkGetCollection ($oIE)
$Counter=1
$avArray = _ArrayCreate ( "test", "test2")

_ArrayDisplay( $avArray, "Whole array" )
_ArrayAdd( $avArray,"Test3")
_ArrayDisplay( $avArray, "Updated Array" )oÝ÷ Ù«­¢+Ø¥¹±Õ±Ðí%¹ÔÌÐì(¥¹±Õ±ÐíÉÉä¹ÔÌÐì((ÀÌØíÍ}UÉ°ôÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹå½ÕÑÕ¹½´½ÉÍÕ±ÑÌýÍÉ¡}ÅÕÉäõ5¥ÍÌ­Q¸­UM­M½ÕÑ ­
ɽ±¥¹µÀíÍÉ õMÉ ÅÕ½Ðì(ÀÌØíÍY¥ôÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹå½ÕÑÕ¹½´½ÝÑ ýØôÅÕ½Ðì(ÀÌØí½%ô}%
ÉÑ ÀÌØíÍ}UÉ°°Ä¤(ÀÌØí½1¥¹­Ìô}%1¥¹­Ñ
½±±Ñ¥½¸ ÀÌØí½%¤(ÀÌØí
½Õ¹ÑÈôÄ(ÀÌØíÙÉÉäô}ÉÉå
ÉÑ ÅÕ½ÐíÑÍÐÅÕ½Ðì°ÅÕ½ÐíÑÍÐÈÅÕ½Ðì¤()½ÈÀÌØí½1¥¹¬%¸ÀÌØí½1¥¹­Ì(%}ÉÉå ÀÌØíÙÉÉä°ÀÌØí½1¥¹¬¹¡É¤)9áÐ()}ÉÉå¥ÍÁ±ä ÀÌØíÙÉÉä°ÅÕ½Ðí]¡½±ÉÉäÅÕ½Ðì¤)}ÉÉå ÀÌØíÙÉÉä°ÅÕ½Ðí   É¥¸ÅÕ½Ðì¤)}ÉÉå¥ÍÁ±ä ÀÌØíÙÉÉä°ÅÕ½ÐíUÁÑÉÉäÅÕ½Ðì
Edited by litlmike
Link to comment
Share on other sites

  • Moderators

#include <IE.au3>
#include <array.au3>
$s_Url = "http://www.youtube.com/results?search_query=Miss+Teen+USA+South+Carolina&search=Search"
$sVid = "http://www.youtube.com/watch?v="
$oIE = _IECreate ($s_Url,1)
$oLinks = _IELinkGetCollection ($oIE)
$aUnique = oLinkUnique($oLinks)
_ArrayDisplay($aUnique)

Func oLinkUnique($oObLink)
    If IsObj($oObLink) = 0 Then Return SetError(1, 0, "")
    Local $sHold = "", $vDelim = Chr(1)
    For $oLink In $oObLink
        If StringInStr($vDelim & $sHold, $vDelim & $oLink.href & $vDelim) = 0 Then
            $sHold &= $oLink.href & $vDelim
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), $vDelim)
    Return SetError(2, 0, "")
EndFunc

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...