Jump to content

Problem in get link _IE


kctvt
 Share

Recommended Posts

Hi there, I got some problem in get the true link from IE. So I need help.

I have about 50 links and more in site, but I only want to get about 5 links.

Now, there're a few links.

http://www.hulahula.com/album.php?profile=1&id=100001441852798

http://www.hulahula.com/franchelink

http://www.hulahula.com/franchelink?sk=list&v=list

http://www.hulahula.com/franche.christ/news/149199628471431

http://www.hulahula.com/profile.php?id=1275759374

http://www.hulahula.com/profile.php?id=100000089022254

http://www.hulahula.com/franche.christ/news/159195624472487

http://www.hulahula.com/permalink.php?numid=149179445140116&id=100001988032272

First , I plan to use :

$link1 = _IELinkGetCollection ($oIE,1)
$link2 = _IELinkGetCollection ($oIE,2)

to get Link from IE. Then :

$Number = number    ;;;;  Problem right here !!!
IF $link1 = ("http://www.hulahula.com/franche.christ/news/"&$Number) then
Msgbox (48, "Note", "True link" ,100)
EndIF

Problem is... I dont know how to the code understand I only want to get links like "http://www.hulahula.com/franche.christ/news/"+ Number

So... I need help @_@ :)

Edited by kctvt
Link to comment
Share on other sites

Try something like.

You should probably take a look at Regular Expressions.

$oLinks =_IELinkGetCollection($oIE)

For $oLink in $oLinks
    if StringInStr($oLink.href, "http://www.hulahula.com/franche.christ/news/") Then
        ConsoleWrite("Link Found: " & $oLink.href & @CRLF)
    EndIf
Next
Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

Oh... Thanks so much Steveiwonder ;) It's working. :)

But , I got a new problem =.=

After this code run

$oLinks =_IELinkGetCollection($oIE)

For $oLink in $oLinks
    if StringInStr($oLink.href, "http://www.hulahula.com/franche.christ/news/") Then
        ConsoleWrite("Link Found: " & $oLink.href & @CRLF)
    EndIf
Next

There are some links I had before. I dont want take them again. So, I creat a log file (Log.txt)

How can I make this code dont take these logged links

Link to comment
Share on other sites

Something like this :)

$oLinks =_IELinkGetCollection($oIE)

For $oLink in $oLinks
    if StringInStr($oLink.href, "http://www.hulahula.com/franche.christ/news/") Then
        $fileContent = FileRead("Log.txt") ; called here so that you can save link to new log and then reload so it doesn't duplicate a link
        If NOT StringInStr($fileContent, $olink.href) Then ; Link doesn't exist in file?
            ConsoleWrite("Link Found: " & $oLink.href & @CRLF)
            ;do savestuff here
        EndIf
    EndIf
Next
Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

Is it just the links in red that you want? If so then you don't really even need the link collection just the page source.

$sSrc = BinaryToString(InetRead("http:\\www.hulahula.com"))
If NOT @Error Then
    $aValidLinks = StringRegExp($sSrc, "(http:\S+christ/news/\d+|http:\S+php\?numid=[id=&\d]+)", 3);; 0 based array
    If NOT @Error Then
        For $i = 0 To Ubound($aValidLinks) -1
            MsgBox(0, "Valid Result " & $i+1, $aValidLinks[$i])
        Next
    EndIf
EndIf

If You still want to use the collection then use the same RegExp like this

$oLinks =_IELinkGetCollection($oIE)

For $oLink in $oLinks
    If NOT StringRegExp($oLink, "(http:\S+christ/news/\d+|http:\S+php\?numid=[id=&\d]+)") Then
        ContinueLoop
    Else
        ;; Do what you want with the link here
    EndIf
Next

NOTE: Written on the fly with only the expression tested using PCRE Toolkit against the examples and assuming the links in red are what you want.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

umm... This is my new code.

Check it

$Links = _IELinkGetCollection ($oIE)

For $Link in $Links
    If StringInStr($Link.href,"http://www.hulahula.com/franche.christ/news/") then
        $fileContent = FileRead("LogLink.txt")
        If StringInStr($fileContent, $Link.href) then
            ConsoleWrite("Old Link Found : " &$Link.href & @CRLF)
        Else
            _IEAction ($Link,"click")
            _IELoadWait ($oIE)
            $Text = _IEBodyReadText ($oIE)
            $URLnow = _IEPropertyGet ($oIE,"locationurl")
            Select
                Case StringInStr($Text, "CALL-Bumba")
                    Msgbox (48, "Notice","Calling Bumba" ,5)
                    _ArrayAdd ($LinkText,$URLnow)
                    _FileWriteFromArray("LogLink.txt",$LinkText, 1)
                    _IENavigate ($oIE,"http://www.hulahula.com/franche.christ/")
                    _IELoadWait ($oIE)
                Case Else
                    Msgbox (48, "Notice","Saving error link" ,5)
                    _ArrayAdd ($LinkText,$URLnow)
                    _FileWriteFromArray("LogLink.txt",$LinkText, 1)
                    _IENavigate ($oIE,"http://www.hulahula.com/franche.christ/")
                    _IELoadWait ($oIE)
            EndSelect
        EndIf
    EndIf
Next

It works very good with the first link "http://www.hulahula.com/franche.christ/news/197894253559137"

But, when the second link run , this code dont work.

Autoit said that :

==> The requested action with this object has failed.:

If StringInStr($Link.href,"http://www.hulahula.com/franche.christ/news/") then

If StringInStr($Link.href^ ERROR

Something wrong ?

Edited by kctvt
Link to comment
Share on other sites

The $Links collection is only valid in that document. Once you do _IEAction($Link, "click") a new document is loaded and all the object references in the $Links collection become invalid.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...