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
#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)
; #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
$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
; ===============================================================================================================================
; 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
MfG