• Hey,
    meine Webspider Funktion ist endlich fertig.
    Sie ist nicht sonderlich schnell und performant, deshalb erhoffe ich Verbesserungen seitens der Community.
    Sie ist außerdem nicht sonderlich ausgereift!


    Spoiler anzeigen
    [autoit]

    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $aLinks[1]

    [/autoit] [autoit][/autoit] [autoit]

    HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1")
    _Webspider($aLinks, "http://www.google.de/", "google.de") ;Andere Webseite nehmen!
    _ArrayDisplay($aLinks)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _Webspider
    ; Description ...: Returns all urls from a specified host
    ; Syntax.........: _Webspider(ByRef $aReturn, $sLink, $sHost)
    ; Parameters ....: $aReturn - Predeclared array where all links are stored in
    ; $sLink - The URL of the site to be crawled (e.g. http://www.google.de/)
    ; $sHost - The host (e.g. google.de)
    ; Return values .: Success - All links are stored in $aReturn
    ; Failure - $aReturn is empty
    ; Author ........: PenGuin (http://www.autoit.de)
    ; Modified.......:
    ; Remarks .......: $aReturn[0] got the arraycount
    ; You should always use HttpSetUserAgent
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes
    ; ===============================================================================================================================
    Func _Webspider(ByRef $aReturn, $sLink, $sHost)
    Local $sSource, $aRegEx, $iUBound

    [/autoit] [autoit][/autoit] [autoit]

    $sSource = BinaryToString(InetRead($sLink))
    $aRegEx = StringRegExp($sSource, '(?:src="|action="|href=")(?!javascript:)([^"#]+)', 3)
    If IsArray($aRegEx) Then
    For $sElement In $aRegEx
    If StringLeft($sElement, 1) <> "/" And StringLeft($sElement, 4) <> "http" Then $sElement = "http://www." & $sHost & "/" & $sElement
    If $sElement = $sLink Then ContinueLoop
    If Not StringInStr($sElement, $sHost) Then ContinueLoop
    If __InternArrSearch($aReturn, $sElement) > -1 Then
    ContinueLoop
    Else
    $iUBound = UBound($aReturn)
    ReDim $aReturn[$iUBound + 1]
    $aReturn[$iUBound] = $sElement
    $aReturn[0] = UBound($aReturn) - 1
    EndIf
    If StringLeft($sElement, 2) = ".." Then ContinueLoop
    If StringInStr($sElement, "\/") Then StringReplace($sElement, "\/", "/")
    _Webspider($aReturn, $sElement, $sHost)
    Next
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; ===============================================================================================================================
    ; INTERNAL USE ONLY
    ; ===============================================================================================================================
    Func __InternArrSearch($aArray, $sValue)
    Local $iUBound, $i
    For $i = 0 To UBound($aArray) - 1
    If $aArray[$i] = $sValue Then Return $i
    Next
    Return -1
    EndFunc

    [/autoit]


    MfG

  • hey :)

    also ich sags so: es funktioniert :D

    aber meine frage ist: was bringt sowas?
    habe sowas schon öfter gesehn auch in anderen "sprachen" wie c++ oder c# aber ich kann mir grade keinen nutzen daraus denken warum man links sammeln sollte^^ :D

    mfg

  • Hallo PenGuin,

    dass es nicht besonders performant ist liegt (neben AutoIt) an dem ReDim in Zeile 41. Du solltest dir eine Methode ausdenken bei dem du die Anzahl der ReDim 's veringern oder vielleich ganz darauf verzichten kannst. Letzteres sollte doch mit

    [autoit]

    _ArrayConcatenate

    [/autoit]

    und

    [autoit]

    _ArrayUnique

    [/autoit]

    möglich sein,

    @killax2x: es ist zum einen eine gute Übung um Rekursionen zu üben bzw. seine Logik zu schulen um performante Algorythmen zu entwickeln, zum anderen ist es die Grundlage um eine Webseite mit all ihren Links downzuloaden um sie nach Anpassng der Links ofline im Zugriff zu haneb,

    mfg autoBert