Jump to content

Checking Dead Link


 Share

Recommended Posts

Just combining some examples from the help file, here is a possible way of doing it. If $size is 0 then you could consider that the document is not there.

#include <IE.au3>
;$oIE = _IE_Example ("basic")
$oIE = _IECreate ( "http://www.example.com/")

$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
    
    $size = InetGetSize ($oLink.href)
    MsgBox(0, "Link Info", $oLink.href & "Size: "& $size)
Next

You might run in to trouble with this being slow, or handling 404 redirects etc, but perhaps this will work for your needs?

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

You could maybe try INetGetSource instead:

#include <IE.au3>
#include <INet.au3>
;$oIE = _IE_Example ("basic")
$oIE = _IECreate ( "http://www.example.com/")

$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks

    ;$size = InetGetSize ($oLink.href)
    _INetGetSource ( $oLink.href )

    ;if $size <> 0 then
    if @ERROR <> 1 then
        filewriteline("log.txt","Good: "& $oLink.href)
    else
        filewriteline("log.txt","Bad: "& $oLink.href)
    endif

Next
Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

the second code you post seem to work. of course it return bad when the link require a password. Is there a way to display where the link is coming from? displaying whatever the text than the link its going to

Edited by tqt129
Link to comment
Share on other sites

Well, if it requires a password, and you don't have it, it's bad anyway, right?

If you wanted to see where the link was being redirected to, you could do something like

;instaniate a new Internet Explorer object, and try and go to the page in question.
$oIE2 = _IECreate ($oLink.href)

;wait for it to load and trigger any redirects etc.
sleep(1000)

;wait for a potential redirect to finish redirecting
_IELoadWait ($oIE2)

$newurl = _IEPropertyGet ($oIE2, "locationurl")
if $newurl <> $oLink.href then filewriteline("log.txt","Bad: "& $oLink.href & @crlf & @tab & "Changed To:"&$newurl)

_IEQuit ($oIE2)

You get the idea

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Well, if it requires a password, and you don't have it, it's bad anyway, right?

If you wanted to see where the link was being redirected to, you could do something like

;instaniate a new Internet Explorer object, and try and go to the page in question.
$oIE2 = _IECreate ($oLink.href)

;wait for it to load and trigger any redirects etc.
sleep(1000)

;wait for a potential redirect to finish redirecting
_IELoadWait ($oIE2)

$newurl = _IEPropertyGet ($oIE2, "locationurl")
if $newurl <> $oLink.href then filewriteline("log.txt","Bad: "& $oLink.href & @crlf & @tab & "Changed To:"&$newurl)

_IEQuit ($oIE2)

You get the idea

actually i want to know where the link is coming from. say a link that say click "HERE" to go to this page. and if that link is bad, display both the word "HERE" and the URL(www.here.com)

thanks alot for helping me on this by the way...good help and learning experience =)

Link to comment
Share on other sites

Oh, I get it.

if @ERROR <> 1 then
        filewriteline("log.txt","Good: "& $oLink.innerText & "[" & $oLink.href & "]")
    else
        filewriteline("log.txt","Bad: "& $oLink.innerText & "[" & $oLink.href & "]")
    endif

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Oh, I get it.

if @ERROR <> 1 then
        filewriteline("log.txt","Good: "& $oLink.innerText & "[" & $oLink.href & "]")
    else
        filewriteline("log.txt","Bad: "& $oLink.innerText & "[" & $oLink.href & "]")
    endif
ok 1 more requestion =). instead of

$oIE = _IECreate ( "http://www.example.com/")

. how about a popup prompt asking what URL i want to look at
Link to comment
Share on other sites

#include <IE.au3>
#include <INet.au3>
;$oIE = _IE_Example ("basic")
$oIE = _IECreate ( InputBox("Question", "Enter URL (www.yahoo.com, netzero.net)", "", "",))

$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks

   ;$size = InetGetSize ($oLink.href)
    _INetGetSource ( $oLink.href )

   ;if $size <> 0 then
    if @ERROR <> 1 then
        filewriteline("good.txt","Good: "& $oLink.innerText & "[" & $oLink.href & "]")
    else
        filewriteline("bad.txt","Bad: "& $oLink.innerText & "[" & $oLink.href & "]")
    endif

Next

this is what i have so far, but when the prompt comes up and if i try to close it out..it still run the scripts and load a blank page with HTTP// url

Link to comment
Share on other sites

Your code works perfectly for me, albeit slowly.

Are you putting in the whole url? Meaning "http://www.google.com" not "www.google.com"? Try putting in a tooltip status monitor, like so:

#include <IE.au3>
#include <INet.au3>
;$oIE = _IE_Example ("basic")
$oIE = _IECreate ( InputBox("Question", "Enter URL (www.yahoo.com, netzero.net)", "", "",))

$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found",1)
For $oLink In $oLinks

   ;$size = InetGetSize ($oLink.href)
   tooltip("Checking: "& $oLink.innerText & "[" & $oLink.href & "]",0,0)
    _INetGetSource ( $oLink.href )

   ;if $size <> 0 then
    if @ERROR <> 1 then
        filewriteline("good.txt","Good: "& $oLink.innerText & "[" & $oLink.href & "]")
    else
        filewriteline("bad.txt","Bad: "& $oLink.innerText & "[" & $oLink.href & "]")
    endif

Next

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Ah. Well, if it's not responding, try killing AutoIt3.exe in TaskManager.

Hey, I should mention, I found a cool 404 detection method posted by DaleHohm right here:

http://www.autoitscript.com/forum/index.php?showtopic=22343

You might be able to use this instead.

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Ah. Well, if it's not responding, try killing AutoIt3.exe in TaskManager.

Hey, I should mention, I found a cool 404 detection method posted by DaleHohm right here:

http://www.autoitscript.com/forum/index.php?showtopic=22343

You might be able to use this instead.

its responding, here do this ...run the program..then hit hte cancel button...even though you hit cancel or click the X ...the script still process

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