Url herausfinden

  • Hi @all

    wie kann ich die geöffnete Internetseite des Firefox auslesen

    Ich hoffe jemand weis wie das geht

  • Ja aber ich meine wie FFCmd die seite ausliest also kein beispiel sondern es hat geheisen es geht mit autoit nicht aber ffcmd ist doch eine autoit funktion

  • Wie? Schau dir halt die UDF an :D
    Oder Kurzversion:
    Die FF.au3 arbeitet über eine Telnet-Schnittstelle in FF die durch das AddOn MozRepl realisiert ist und ermöglicht darüber den Zugriff auf gesamten Browser, nicht nur auf die dargestellte Seite.

  • Ok ich habe jezt mozrepl im ff instaliert und gestartet wie kann ich jetzt so einen befehl an ff senden mit autoit ? Ohne der FF.au3

  • Ohne der FF.au3? Bist du dir sicher?

    Voraussetzungen:
    * Erst mal die Anleitung zu MozRepl durchlesen
    * HTML/JavaScript/DOM im Schlaf beherrschen
    * XPath wäre auch nicht schlecht
    * den Inhalt des MDN halbwegs überblicken: https://developer.mozilla.org/En
    * die Sachen die dort nicht (offensichtlich) stehen, bekommt man aber auch durch das Zerlegen des Browser-Source-Codes heraus

    Dann per AutoIt:
    1 per TCP eine Verbindung zu MozRepl aufbauen
    2 auf Antwort warten
    3 Antwort auswerten
    4 evtl. Fehler abfangen
    5 Befehle in Form von JavaScript senden, dabei evtl. Wrapper für sicherheitkritische Sachen beachten
    6 GOTO 2

    evtl. dort die ersten Versuche ansehen:
    FF-Management - FireFox.au3
    FF-Management - FireFox.au3

  • Warum geht dann folgendes nicht

    Spoiler anzeigen
    [autoit]


    Global $Firefox_connect

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

    _FirefoxConnect()
    $sURL = _FirefoxCmd(".location.href")
    MsgBox(0,"",$sURL)

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

    Func _FirefoxConnect()
    $IP = "127.0.0.1"
    $iPort = 4242

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

    TCPStartup()

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

    While 1
    $Firefox_connect = TCPConnect($IP, $iPort)
    WENd
    IF $Firefox_connect <> -1 Then
    If _FFWaitForRepl(10000) Then
    ConsoleWrite("Browser is connected")
    Endif
    else
    TCPShutdown()
    endif
    EndFunc

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

    Func _FirefoxCmd($Firefox_command)
    $Firefox_command = "window.content.wrappedJSObject.document" & $Firefox_command
    _FirefoxSend($Firefox_command)
    Endfunc

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

    Func _FirefoxSend($sCommand)
    TCPSend($Firefox_connect, $sCommand & @CRLF)
    EndFunc

    [/autoit]
  • Wo kommt denn die Funktion "_FFWaitForRepl" her?
    Du rufst die zwar auf, die ist aber nicht vorhanden.

    Aus der Schleife:

    [autoit]

    While 1
    $Firefox_connect = TCPConnect($IP, $iPort)
    WENd

    [/autoit]


    Kommt das Programm nie wieder heraus.

    Wenn du was gesendet hast, dann mußt du auch die Antwort von MozRepl auch abholen

    "window.content.wrappedJSObject.document" ist nicht bei jeder Art von Befehl richtig.

    Auf Frames bekommst du mit diesem Aufbau der Funktionen auch keinen Zugriff.

    Wenn einen falschen JavaScript-Befehl abschickst, bringt MozRepl auch einen Fehler, den du wieder zurücksetzen muß, sonst geht gar nichts mehr, oder schickst eben ein try/catch mit.

    Und vor allem - warum möchtest du die ganzen Funktionen denn neu bauen?

  • Um die FF.au3 besser zu verstehen und um zu lernen.

    Wie muss ich es dann richtig machen ? bei der funktion habe ich einen unterstrich vergessen
    Und wie komme ich aus der schleife wieder heraus?

  • Die While Schleife kannst du weglassen, entweder die Verbindung wird aufgebaut oder nicht.

    Die Kommunikation und die eigentliche "Bedienung" von FF sind zwei vollkommen verschiedene Sachen.

    Die Bedienung erfolgt rein über das Senden von JavaScript-Befehlen und die Kommunkation ist reines Telnet.
    Also eins nach dem anderen :)

    Schau dir mal das dort an:
    FF-Management - FireFox.au3
    das ein einfaches Telnet Programm, mit dem du direkt z.B. auf MozRepl zugreifen kannst, vielleicht wird die Kommunaktion damit klarer.

    Das ganze Drumherum bei __FFWaitForRepl usw. ist nötig um die empfangenen Daten auszuwerten.

    Wenn das alles funktioniert, kommen die eigentlichen Funktionen, wobei bei denen meistens 90% der Funktion aus einer Auwertung der Übergabeparameter besteht.

    Was dann eigentlich an FF gesendet wird, kannst du (größtenteils zumindest) mit der neuen Testversion ausprobieren:
    Neue Funktionen und ToDo-List
    damit lassen sich die Befehle aufzeichnen die gesendet werden.

    Aus einem:

    [autoit]

    _FFSetValueByName("fname", "Vorname")

    [/autoit]


    wird dann im Endeffekt:

    [autoit]

    _FFCmd(".getElementsByName('fname')[0].value='Vorname';")

    [/autoit]
  • Ok danke

    Wie muss ich folgendes umändern damit die url herauskommt

    Spoiler anzeigen
    [autoit]

    Global $Firefox_connect

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

    $socket = _FirefoxConnect()

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

    $sURL = _FirefoxCmd("content.frames[0].document.location.href")
    MsgBox(0,"",$sURL)

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

    Func _FirefoxConnect()
    $IP = "127.0.0.1"
    $iPort = 4242

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

    TCPStartup()

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

    $Firefox_connect = TCPConnect($IP, $iPort)

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

    IF $Firefox_connect <> -1 Then
    If _FirefoxWait() Then
    return $Firefox_connect
    else
    return -1
    Endif
    else
    TCPShutdown()
    endif
    EndFunc

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

    Func _FirefoxCmd($Firefox_command)
    _FirefoxSend($Firefox_command)
    $return = _FirefoxRecv()
    Return $return
    Endfunc

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

    Func _FirefoxSend($sCommand)
    TcpSend($Firefox_connect,$sCommand & @CRLF )
    EndFunc

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

    Func _FirefoxWait()

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

    Local $i = 0
    Local $return = 1

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

    While 1
    $recv = TCPRecv($Firefox_connect,4096)
    If @error Then
    $return = 0
    ExitLoop
    Endif
    If StringInStr($recv,"repl>") Then
    ExitLoop
    Endif
    $i += 1
    If $i > 10 Then
    ExitLoop
    Endif
    WEnd

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

    Return $return

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

    EndFunc

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

    Func _FirefoxRecv()
    Local $sRet = _FirefoxWait()
    Return $sRet
    EndFunc

    [/autoit]
  • So gehts:

    Spoiler anzeigen
    [autoit]

    Global $Firefox_connect

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

    If _FirefoxConnect() Then
    Global $sURL = _FirefoxCmd("window.content.document.location.href")
    MsgBox(0, "", $sURL)
    EndIf

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

    ; ==============================================================================
    Func _FirefoxConnect()
    Local $IP = "127.0.0.1"
    Local $iPort = 4242

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

    TCPStartup()

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

    $Firefox_connect = TCPConnect($IP, $iPort)

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

    If $Firefox_connect <> -1 Then
    If _FirefoxWait() Then
    Return 1
    Else
    Return 0
    EndIf
    Else
    TCPShutdown()
    EndIf
    EndFunc ;==>_FirefoxConnect
    ; ==============================================================================
    Func _FirefoxCmd($Firefox_command)
    _FirefoxSend($Firefox_command)
    Return _FirefoxRecv()
    EndFunc ;==>_FirefoxCmd

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

    ; ==============================================================================
    Func _FirefoxSend($sCommand)
    TCPSend($Firefox_connect, $sCommand & @CRLF)
    EndFunc ;==>_FirefoxSend
    ; ==============================================================================
    Func _FirefoxWait()

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

    Local $sReturn = '', $recv

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

    Local $TimeOutTimer = TimerInit()
    While TimerDiff($TimeOutTimer) < 5000
    $recv = TCPRecv($Firefox_connect, 4096)
    ConsoleWrite($recv)
    If @error Then ExitLoop
    $sReturn &= $recv

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

    If StringRegExp($recv, "!!!(.*?)(TypeError|Exception|ReferenceError):?") Then
    $recv = StringLeft($recv, StringInStr($recv, "location") - 1)
    SetError(1)
    Return ""
    ElseIf StringInStr($recv, "....>") Then
    _FirefoxSend(";") ; MozRepl-Reset
    Sleep(100)
    SetError(2)
    Return ""
    ElseIf StringInStr($recv, "beginning of the line to force evaluation") Then
    Sleep(500) ; first connection delay
    EndIf

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

    If StringRegExp($recv, "repl[\d]?>") Then Return StringRegExpReplace($sReturn, "repl[\d]?>", "")

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

    WEnd

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

    Return ''
    EndFunc ;==>_FirefoxWait
    ; ==============================================================================
    Func _FirefoxRecv()
    Local $sRet = _FirefoxWait()
    $sRet = StringStripWS($sRet, 3) ; Leerzeichen entfernen
    ; Anführungszeichen am Anfang und Ende entfernen
    If StringLeft($sRet, 1) = '"' Then $sRet = StringTrimLeft($sRet, 1)
    If StringRight($sRet, 1) = '"' Then $sRet = StringTrimRight($sRet, 1)
    Return $sRet
    EndFunc ;==>_FirefoxRecv

    [/autoit]