Sign in to follow this  
Followers 0
Slythfox

Retrieve website link

16 posts in this topic

This is what I'm trying to do:

1. I want to download a website's html contents.

2. Save all the link urls (<a href="">) to an array.

3. Look through the array for an identifier: ex: if the indentifier was ".exe", the file "foobar.exe" would be found.

4. Display the array that contained that indentifier. ex: display "foobar.exe"

This is only part of a program I'm working on. I only really need help with steps 2 and 3.

Thanks.

Share this post


Link to post
Share on other sites



I use InetGetSource() and _SRE_Between() for stuff like this... I'm sure others use IE.au3.


[center]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.[/center]

Share this post


Link to post
Share on other sites

from "Welcome to Autoit 1-2-3".... ( in my sig )

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>

#Region --- IE-Builder generated code Start ---

$oIE = _IECreate ()

;------------- User input --------------
_IENavigate ($oIE, "http://www.autoitscript.com/") ; web address
$Find = "LZ" ; my info shows after this line... or just find this line
$Before = "comp"    ; my info shows before this line... or set as ""
; ------------ End User input -------------
Sleep(1000)
$body =  _IEBodyReadHTML ($oIE)
$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
FileWrite($sloc, $body)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "    ", 5)
        ExitLoop
    EndIf
WEnd

Func stringbetween($str, $start, $end)
    $pos = StringInStr($str, $start)
    If Not @error Then
        $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
        $pos = StringInStr($str, $end)
        If Not @error Then
            $str = StringTrimRight($str, StringLen($str) - $pos + 1)
            Return $str
        EndIf
    EndIf
EndFunc   ;==>stringbetween

#EndRegion --- IE-Builder generated code End ---

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

from "Welcome to Autoit 1-2-3".... ( in my sig )

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>

#Region --- IE-Builder generated code Start ---

$oIE = _IECreate ()

;------------- User input --------------
_IENavigate ($oIE, "http://www.autoitscript.com/") ; web address
$Find = "LZ" ; my info shows after this line... or just find this line
$Before = "comp"    ; my info shows before this line... or set as ""
; ------------ End User input -------------
Sleep(1000)
$body =  _IEBodyReadHTML ($oIE)
$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
FileWrite($sloc, $body)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "    ", 5)
        ExitLoop
    EndIf
WEnd

Func stringbetween($str, $start, $end)
    $pos = StringInStr($str, $start)
    If Not @error Then
        $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
        $pos = StringInStr($str, $end)
        If Not @error Then
            $str = StringTrimRight($str, StringLen($str) - $pos + 1)
            Return $str
        EndIf
    EndIf
EndFunc   ;==>stringbetween

#EndRegion --- IE-Builder generated code End ---

oÝ÷ ÛÏêº^.$²X¤zØZ¶ËkxzÜzw(ºW[zkÉhÁêí©íê-êö¢b¢{jRn²ÑX!«­¢+Ø)Õ¹}MI}   Ñݹ` ÀÌØíÍ}MÑÉ¥¹°ÀÌØíÍ}MÑÉаÀÌØíÍ}¹°ÀÌØí¥
ÍôÌäí¤Ìäì¤(%%ÀÌØí¥
ͱÐìÐìÌäí¤ÌäìQ¡¸ÀÌØí¥
ÍôÌäìÌäì($ÀÌØí}ÉÉäôMÑÉ¥¹IáÀ ÀÌØíÍ}MÑÉ¥¹°Ìäì üÌäìµÀìÀÌØí¥
͵Àì|($$$ÌäìèÌäìµÀìÀÌØíÍ}MÑÉеÀìÌäì¤ ¸¨ü¤ üÌäìµÀìÀÌØí¥
͵Àì|($$$ÌäìèÌäìµÀìÀÌØíÍ}¹µÀìÌäì¤Ìäì°Ì¤(%%áѹµÀì%ÍÉÉä ÀÌØí}ÉÉä¤Q¡¸IÑÕɸÀÌØí}ÉÉä(%IÑÕɸMÑÉÉ½È Ä°À°À¤)¹Õ¹ìôôÐí}MI} Ñݹ`oÝ÷ Ù«­¢+ÙÕ¹}MÑÉ¥¹  Ñݸ ÀÌØíÍ}MÑÉ¥¹°ÀÌØíÍ}MÑÉаÀÌØíÍ}¹ôÀ¤(ÀÌØíÍ}MÑÉÐôMÑÉ¥¹%¹MÑÈ ÀÌØíÍ}MÑÉ¥¹°ÀÌØíÍ}MÑÉФ­MÑÉ¥¹1¸ ÀÌØíÍ}MÑÉФ(ÉÑÕɸMÑÉ¥¹5¥ ÀÌØíÍ}MÑÉ¥¹°ÀÌØíÍ}MÑÉаMÑÉ¥¹%¹MÑÈ ÀÌØíÍ}MÑÉ¥¹°ÀÌØíÍ}¹¤´ÀÌØíÍ}MÑÉФ)¹Õ¹

[center]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.[/center]

Share this post


Link to post
Share on other sites

This should do the job.

#include <IE.au3>

$sURL = "http://www.autoitscript.com/autoit3/downloads.php"
$oIE = _IECreate($sURL)
$oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    $shref = $oLink.href
    If StringRight($shref, 4) = ".exe" Then
        $aLink = StringSplit($shref, "/")
        ConsoleWrite($aLink[$aLink[0]] & @CRLF)
    EndIf
Next

ok ! How can i read from the console ? Consoleread not exists ..

StdoutRead not working for me .....

Big daddys code is short without many complications . !

Share this post


Link to post
Share on other sites

Thanks. I got it. I am using the code from "Welcome to Autoit 1-2-3," heavily modified, and doesn't use that IE stuff.

Share this post


Link to post
Share on other sites

ok ! How can i read from the console ? Consoleread not exists ..

StdoutRead not working for me .....

Big daddys code is short without many complications . !

If you are using SciTE as your editor then check the output pane at the bottom of the window.

Share this post


Link to post
Share on other sites

Hey All

I understand what this code is doing and have modified it to perform the function I wanted but (and I have a feeling this is going to sound stupid) what is the loop waiting on...

it says while 2, my question is while what is 2, what is the while waiting for...?

While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "    ", 5)
        ExitLoop
    EndIf
WEnd

8)

Share this post


Link to post
Share on other sites

it says while 2, my question is while what is 2, what is the while waiting for...?

Any integer greater than zero will evaluate to true, "While True" would have the same effect. This meaning while the expression evaluates to true then continue the loop, but if it evaluates to false then the loop is exited.

Share this post


Link to post
Share on other sites

Any integer greater than zero will evaluate to true, "While True" would have the same effect. This meaning while the expression evaluates to true then continue the loop, but if it evaluates to false then the loop is exited.

Thanks mate.

If I can just clarify here: While 2 means that if the "while loop" generates an error, then the "while loop" is exited other wise it continues to loop... correct ?

Share this post


Link to post
Share on other sites

no it just means while 1 = 1 or while 2 = 2 but its shortened, but yes if you have 2 while loops back to back, and you put in a condition to exit the loop (exitloop) then yes it will go to the next bit of code which will just happen to be another while loop

Share this post


Link to post
Share on other sites

no it just means while 1 = 1 or while 2 = 2 but its shortened, but yes if you have 2 while loops back to back, and you put in a condition to exit the loop (exitloop) then yes it will go to the next bit of code which will just happen to be another while loop

:nuke: wheres the second while loop, Am I missing somthing ? :P

Let me rephrase the last question.

In this case, what expression must = 2 (or true) for the loop to continue

While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "    ", 5)
        ExitLoop
    EndIf
WEnd

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

:nuke: wheres the second while loop, Am I missing somthing ? :P

Let me rephrase the last question.

In this case, what expression must = 2 (or true) for the loop to continue

While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "    ", 5)
        ExitLoop
    EndIf
WEnd

oÝ÷ Ûú®¢×¢Æ²x-«bµÚ²{fjÛ^¯Z¶{¦mêò¢ênµ§íz»a{bè­ZÞiØ­jÈÊ°z·¬k(§hbí
Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

Sorry mate but i am not asking about the the value of while

from what big_daddy said

Any integer greater than zero will evaluate to true, "While True" would have the same effect. This meaning while the expression evaluates to true then continue the loop, but if it evaluates to false then the loop is exited.

I understand the it does not care if its 1, 2, 5 ect. so long as the value is an integer it is "true" so the loop continues...

What I am trying to understand is what expression must be true for the while loop to continue...

Is it the while loop itsself ?

Share this post


Link to post
Share on other sites

$i = 0
While $i <= 10
    MsgBox(0, "Value of $i is:", $i)
    $i = $i + 1
WEnd

In this case I can see that the while loop will finish when $i has attained a value of 10, so it should loop 10 times....

Share this post


Link to post
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
Sign in to follow this  
Followers 0