lamancha
Goto Top

Brauche Webseite als .txt per Batch: wget liefert nur Teile, Chrome würde alles speichern

Hallo,

ich brauche den Inhalt einer Webseite als .txt-Datei (genau genommen will ich den Vario-Preis einer ganz bestimmten AIDA-Reise überwachen). Dazu habe ich diese .bat geschrieben:
cd C:\Gm\GmCDsDownloads\wget_1_14
Rem @echo off
set webadresse="www.aida.de/kreuzfahrt/angebote-buchen/reisesuche.18736.html?screen=SearchBox&tx_aidadyncatalog_catalog%5BcruiseListPage%5D=0&tx_aidadyncatalog_catalog%5BpaxConfig%5D=0&tx_aidadyncatalog_catalog%5BsearchState%5D=&tx_aidadyncatalog_catalog%5Bregion_or_ship%5D=ship&tx_aidadyncatalog_catalog%5BsearchRegionShipCode%5D=SO&tx_aidadyncatalog_catalog%5Bharbour_or_poc%5D=harbour&tx_aidadyncatalog_catalog%5BsearchPortCode%5D=*0&tx_aidadyncatalog_catalog%5BsearchStartDate%5D=14.12.2013&tx_aidadyncatalog_catalog%5BsearchEndDate%5D=21.12.2013&tx_aidadyncatalog_catalog%5BsearchEarlyBird%5D=*0&tx_aidadyncatalog_catalog%5BsearchPriceCode%5D=*0&tx_aidadyncatalog_catalog%5BsearchDurationCode%5D=*0&tx_aidadyncatalog_catalog%5BsearchSpecials%5D=*0&tx_aidadyncatalog_catalog%5BsearchTransportation%5D=Z&SearchButton="  
Rem Dateiname + Pfad vordefinieren
set dateiname=webseite.txt
set pfad=AIDAvario
REM -------------------------------------------------------
if not exist AIDAvario mkdir AIDAvario
wget %webadresse% -O %pfad%\%dateiname% 
pause
start chrome.exe "www.aida.de/kreuzfahrt/angebote-buchen/reisesuche.18736.html?screen=SearchBox&tx_aidadyncatalog_catalog%5BcruiseListPage%5D=0&tx_aidadyncatalog_catalog%5BpaxConfig%5D=0&tx_aidadyncatalog_catalog%5BsearchState%5D=&tx_aidadyncatalog_catalog%5Bregion_or_ship%5D=ship&tx_aidadyncatalog_catalog%5BsearchRegionShipCode%5D=SO&tx_aidadyncatalog_catalog%5Bharbour_or_poc%5D=harbour&tx_aidadyncatalog_catalog%5BsearchPortCode%5D=*0&tx_aidadyncatalog_catalog%5BsearchStartDate%5D=14.12.2013&tx_aidadyncatalog_catalog%5BsearchEndDate%5D=21.12.2013&tx_aidadyncatalog_catalog%5BsearchEarlyBird%5D=*0&tx_aidadyncatalog_catalog%5BsearchPriceCode%5D=*0&tx_aidadyncatalog_catalog%5BsearchDurationCode%5D=*0&tx_aidadyncatalog_catalog%5BsearchSpecials%5D=*0&tx_aidadyncatalog_catalog%5BsearchTransportation%5D=Z&SearchButton="  
wget liefert nur 6 KB und nicht die Zeichenfolgen, die ich brauche.

Wenn ich aber chrome.exe ausführe und dann per Hand "Speichern unter ..." mit "Webseite, nur HTML" aufrufe, bekomme ich 116 KB und darin auch das, was ich brauche.

Aber eigentlich soll die vollständige Seite aus dem Skript heraus gespeichert werden. Es wäre schön, hierzu eine Hilfe zu bekommen. Ich bin auch gerne bereit, das Problem anders zu lösen - wenn es denn nur funktionieren würde.

Content-Key: 218098

Url: https://administrator.de/contentid/218098

Printed on: April 25, 2024 at 04:04 o'clock

Member: colinardo
colinardo Sep 28, 2013 updated at 17:50:15 (UTC)
Goto Top
Hallo LaMancha,
hierzu kannst du folgendes AutoIt-Script nehmen:
#NoTrayIcon
#include <ie.au3>
SplashTextOn("","Frage Preise für Aida-Reise ab...","400","50","-1","-1",35,"","","")  
$objIE = _IECreate("http://www.aida.de/kreuzfahrt/angebote-buchen/reisesuche.18736.html?screen=SearchResult&tx_aidadyncatalog_catalog[cruiseListPage]=0&tx_aidadyncatalog_catalog[paxConfig]=0&tx_aidadyncatalog_catalog[searchState]=&tx_aidadyncatalog_catalog[region_or_ship]=ship&tx_aidadyncatalog_catalog[searchRegionShipCode]=SO&tx_aidadyncatalog_catalog[harbour_or_poc]=harbour&tx_aidadyncatalog_catalog[searchPortCode]=*0&tx_aidadyncatalog_catalog[searchStartDate]=14.12.2013&tx_aidadyncatalog_catalog[searchEndDate]=21.12.2013&tx_aidadyncatalog_catalog[searchEarlyBird]=*0&tx_aidadyncatalog_catalog[searchPriceCode]=*0&tx_aidadyncatalog_catalog[searchDurationCode]=*0&tx_aidadyncatalog_catalog[searchSpecials]=*0&tx_aidadyncatalog_catalog[searchTransportation]=Z&SearchButton=",0,0,1)  
$price_table = _IETableGetCollection($objIE,0)
$tableText = $price_table.innerText
_IEQuit($objIE)
$strVarioPreise = StringRegExp($tableText,'(VARIO Preis[\s\S]*?)PREMIUM Preis \*',3)  
$f = FileOpen(@DesktopDir & "\Preise.txt",2)  
FileWrite($f,$tableText)
FileClose($f)
SplashOff()
msgbox(64,"Vario-Preise der Aida Reise", $strVarioPreise)  
Es extrahiert die Vario-Preise aus der Tabelle und zeigt sie dir mit einer MessageBox an. Zusätzlich speichert es die ganze Preistabelle in einer Textdatei namens "Preise.txt" auf dem Desktop.
Wenn AutoIt jetzt nicht installieren willst kannst du dir die kompilierte direkt ausführbare Datei hier herunterladen.

Ansonsten kannst du auch folgendes Powershell-Script dafür nehmen:
$objIE = New-Object -ComObject "InternetExplorer.Application"  
echo "Bitte warten..."  
$objIE.Navigate('http://www.aida.de/kreuzfahrt/angebote-buchen/reisesuche.18736.html?screen=SearchResult&tx_aidadyncatalog_catalog[cruiseListPage]=0&tx_aidadyncatalog_catalog[paxConfig]=0&tx_aidadyncatalog_catalog[searchState]=&tx_aidadyncatalog_catalog[region_or_ship]=ship&tx_aidadyncatalog_catalog[searchRegionShipCode]=SO&tx_aidadyncatalog_catalog[harbour_or_poc]=harbour&tx_aidadyncatalog_catalog[searchPortCode]=*0&tx_aidadyncatalog_catalog[searchStartDate]=14.12.2013&tx_aidadyncatalog_catalog[searchEndDate]=21.12.2013&tx_aidadyncatalog_catalog[searchEarlyBird]=*0&tx_aidadyncatalog_catalog[searchPriceCode]=*0&tx_aidadyncatalog_catalog[searchDurationCode]=*0&tx_aidadyncatalog_catalog[searchSpecials]=*0&tx_aidadyncatalog_catalog[searchTransportation]=Z&SearchButton=')  
while($objIE.Busy){
    sleep(1)
}
$objPriceTable = $objIE.document.getElementsByTagName("table")  
$objPriceTable |select -Index 0 | %{$_.innerText}| Out-File "$((get-item env:UserProfile).Value)\Desktop\Preise.txt"  
echo "Fertig"  
$objIE.Quit()
Falls du Powershell noch nie genutzt hast, musst du einmal in einer Powershell mit Admin-Rechten folgenden Befehl ausführen:
Set-ExecutionPolicy RemoteSigned

Grüße Uwe
Member: Lochkartenstanzer
Lochkartenstanzer Sep 28, 2013 updated at 18:12:36 (UTC)
Goto Top
Moin,

Ganz einfach: Die Seite ist Javascript-verseucht. chrome interpretiert das Javascript und präsentiert Dir das ergebnis beim abspeichern.

wget läßt javascript javascript sein und speichert das ohne es zu interpretieren.

lks
Member: LaMancha
LaMancha Sep 29, 2013 at 12:34:54 (UTC)
Goto Top
Hallo colinardo,

herzlichen Dank für die Lösungsansätze. Da ich bisher weder mit AutoIt noch mit Powershell zu tun hatte, habe ich erst einmal mit AutoIt angefangen.

Mit der kompilierten exe bekam ich beim ersten Aufruf die Meldung:
AutoIt Error: Line 2603 (File "C:\...\Aida-Preis+abfragen.exe): Error: Variable must be of type "Object".

Dann habe ich AutoIt installiert und das Skript nachgebaut, für meine Umgebung auch etwas erweitert und angepasst. Das sieht jetzt so aus:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
	Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#NoTrayIcon
#include <IE.au3>
;SplashTextOn("","Frage Preise für Aida-Reise ab...","400","50","-1","-1",35,"","","")  
$objIE = _IECreate("http://www.aida.de/kreuzfahrt/angebote-buchen/reisesuche.18736.html?screen=SearchResult&tx_aidadyncatalog_catalog[cruiseListPage]=0&tx_aidadyncatalog_catalog[paxConfig]=0&tx_aidadyncatalog_catalog[searchState]=&tx_aidadyncatalog_catalog[region_or_ship]=ship&tx_aidadyncatalog_catalog[searchRegionShipCode]=SO&tx_aidadyncatalog_catalog[harbour_or_poc]=harbour&tx_aidadyncatalog_catalog[searchPortCode]=*0&tx_aidadyncatalog_catalog[searchStartDate]=14.12.2013&tx_aidadyncatalog_catalog[searchEndDate]=21.12.2013&tx_aidadyncatalog_catalog[searchEarlyBird]=*0&tx_aidadyncatalog_catalog[searchPriceCode]=*0&tx_aidadyncatalog_catalog[searchDurationCode]=*0&tx_aidadyncatalog_catalog[searchSpecials]=*0&tx_aidadyncatalog_catalog[searchTransportation]=Z&SearchButton=",0,0,1)  
;
$sText = _IEBodyReadHTML($objIE)
$sPath1 = "C:\Gm\GmOTH\oth_2013_ws\sap1\txt\Z00S00_VARIO1_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC  
$f = FileOpen($sPath1,10)
FileWrite($f,$sText)
FileClose($f);
;
$sText = _IEBodyReadText($objIE)
$sPath2 = "C:\Gm\GmOTH\oth_2013_ws\sap1\txt\Z00S00_VARIO2_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC  
$f = FileOpen($sPath2,10)
FileWrite($f,$sText)
FileClose($f);
;
$price_table = _IETableGetCollection($objIE,0)
$tableText = $price_table.innerText
$sPath3 = "C:\Gm\GmOTH\oth_2013_ws\sap1\txt\Z00S00_VARIO3_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC  
$f = FileOpen($sPath3,10)
FileWrite($f,$tableText)
FileClose($f)
;
$strVarioPreise = StringRegExp($tableText,'(VARIO Preis[\s\S]*?)PREMIUM Preis \*',3)  
$sPath4 = "C:\Gm\GmOTH\oth_2013_ws\sap1\txt\Z00S00_VARIO4_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC  
$f = FileOpen($sPath4,10)
FileWrite($f,$tableText)
FileClose($f)
;
_IEQuit($objIE)
;SplashOff()
;msgbox(64,"Vario-Preise der Aida Reise", $strVarioPreise)  

Damit habe ich jetzt 4 Formate, die ich weiterverarbeiten kann. Vielen Dank!

Und wenn ich noch eine Frage stellen darf: Wäre AutoIt auch geeignet, diese Anforderung zu realisieren?:
Wenn der Vario-Preis für die Innenkabine unter 449 Euro fällt, soll ein Email versendet werden. Das "wie" wäre dann natürlich eine andere Diskussion.

MfG - LaMancha
Member: LaMancha
LaMancha Sep 29, 2013 at 12:40:30 (UTC)
Goto Top
Hallo Lochkartenstanzer,

komisch an der Webseite ist, dass sie manchmal auch mit wget ohne Probleme gelesen werden kann. Ich frage mich, ob es bei Typo3 (womit die Seite wohl generiert wird) eine Option gibt, dass mit oder ohne Javascript generiert wird, und ob diese Option von AIDA mal so und mal anders eingestellt wird?
Member: colinardo
colinardo Sep 29, 2013 updated at 13:08:08 (UTC)
Goto Top
Zitat von @LaMancha:
Mit der kompilierten exe bekam ich beim ersten Aufruf die Meldung:
AutoIt Error: Line 2603 (File "C:\...\Aida-Preis+abfragen.exe): Error: Variable must be of type "Object".
Könnte sein das ich das Script aus versehen als 64Bit kompiliert habe, kenne jetzt dein BS nicht.
Und wenn ich noch eine Frage stellen darf: Wäre AutoIt auch geeignet, diese Anforderung zu realisieren?:
Wenn der Vario-Preis für die Innenkabine unter 449 Euro fällt, soll ein Email versendet werden.
Sicher das ist kein Problem, könnte ich dir zusammenbauen...

Grüße Uwe
Member: colinardo
colinardo Sep 29, 2013 updated at 14:40:26 (UTC)
Goto Top
So hier das Script mit Mail-Alert wenn der Preis kleiner als 449€ ausfällt.
Die Mailserver-Daten zwischen Zeile 25 und 35 musst du natürlich an deine Gegebenheiten anpassen...
(Das Script ist schon auf stum geschaltet, wenn kein Fehler auftritt, ansonsten kommt eine Fehlermeldung die sich automatisch nach 5 Sekunden schließt [Zur Fehlersuche beim Mailversand mit eingebaut]).
Zum testen der Mailfunktion kannst du ja in Zeile 24 den Preisvergleich von "< 449" auf "= 449" setzen.
Die Mail-Funktion unterstützt Authentifizierung und SSL-Verschlüsselung, was die in AutoIt integrierte Funktion nicht bietet. Weitere Infos zu dem Optionen steht in den Kommentaren zur Funktion.

Viel Spaß...
"Mast und Schotbruch" wenn's denn soweit ist face-wink

Grüße Uwe

#NoTrayIcon
#include <IE.au3>
#Include <file.au3>
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyComErrFunc")  
Global $preis_vario = ""  
$objIE = _IECreate("http://www.aida.de/kreuzfahrt/angebote-buchen/reisesuche.18736.html?screen=SearchResult&tx_aidadyncatalog_catalog[cruiseListPage]=0&tx_aidadyncatalog_catalog[paxConfig]=0&tx_aidadyncatalog_catalog[searchState]=&tx_aidadyncatalog_catalog[region_or_ship]=ship&tx_aidadyncatalog_catalog[searchRegionShipCode]=SO&tx_aidadyncatalog_catalog[harbour_or_poc]=harbour&tx_aidadyncatalog_catalog[searchPortCode]=*0&tx_aidadyncatalog_catalog[searchStartDate]=14.12.2013&tx_aidadyncatalog_catalog[searchEndDate]=21.12.2013&tx_aidadyncatalog_catalog[searchEarlyBird]=*0&tx_aidadyncatalog_catalog[searchPriceCode]=*0&tx_aidadyncatalog_catalog[searchDurationCode]=*0&tx_aidadyncatalog_catalog[searchSpecials]=*0&tx_aidadyncatalog_catalog[searchTransportation]=Z&SearchButton=",0,0,1)  
if $objIE = 0 and @error <> 0 then ExitError("Internet-Explorer Objekt")  
_IELoadWait($objIE,1000,60000)
if @error = 6 then ExitError("IE Load Timeout")  
$tags = _IETagNameGetCollection($objIE,"span")  
if @error <> 0 then ExitError("Konnte Tags nicht finden")  
$counter = 1
for $tag in $tags
	if String($tag.className) = "amount" then  
		If $counter = 2 then
			$preis_vario = Number($tag.innerText)
			ExitLoop
		Else
			$counter = $counter + 1
		Endif
	Endif
Next
if $preis_vario <> "" and $preis_vario < 449 then  
	$strSmtpServer = "[SMTPSERVER]"  
	$strFromName = "[ABSENDERNAME]"  
	$strFromAddress = "[FROM_EMAIL_ADDRESS]"  
	$strTo = "[TO_EMAIL_ADDRESS]"  
	$strSubject = "Preis der Aida Reise hat sich reduziert"  
	$strBody = "Der Preis der Reise hat sich verringert, er beträgt jetzt: <strong>" & $preis_vario & "</strong> Euro"  
	$strImportance = "High"  
	$strUsername = "[SMTP_USERNAME]"  
	$strPassword = "[SMTP_PASSWORD]"  
	$strPort = 25
	$strUseSSL = False
	$ret = _SmtpMailAuth($strSmtpServer,$strFromName,$strFromAddress,$strTo,$strSubject,$strBody,"","","",$strImportance,$strUsername,$strPassword,$strPort,$strUseSSL)  
	If @error Then
		MsgBox(48, "Fehler beim senden der Nachricht", "Fehlercode:" & @error & "  Beschreibung:" & $ret,5)  
	EndIf
Endif
_IEQuit($objIE)
exit

; ------------------Helper Functions ---------------------------------

func ExitError($strError)
	msgbox(48,"Error", "Es ist ein Fehler aufgetreten: " & $strError,5)  
	exit 1
EndFunc

; Parameters for Function _SmtpMailAuth
;##################################
;~ $s_SmtpServer = ""                            ; address for the smtp-server to use - REQUIRED  
;~ $s_FromName = "User"                          ; name from who the email was sent  
;~ $s_FromAddress = ""                           ; address from where the mail should come  
;~ $s_ToAddress = ""                             ; destination address of the email - REQUIRED  
;~ $as_Subject = "testsubject"                       ; subject from the email - can be anything you want it to be  
;~ $as_Body = "This Is The Body"                  ; the messagebody from the mail - can be left blank but then you get a blank mail  
;~ $s_AttachFiles = ""                           ; the file you want to attach- leave blank if not needed  
;~ $s_CcAddress = ""                             ; address for cc - leave blank if not needed  
;~ $s_BccAddress = ""                            ; address for bcc - leave blank if not needed  
;~ $_sImportance = "Normal"                      ; Send message priority: "High", "Normal", "Low"  
;~ $s_Username = ""                              ; username for the account used from where the mail gets sent - REQUIRED  
;~ $s_Password = ""                              ; password for the account used from where the mail gets sent - REQUIRED  
;~ $IPPort = 25                               ; port used for sending the mail
;~ $ssl = 0                                    ; enables/disables secure socket layer sending - put to 1 if using httpS


Func _SmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)  
    Local $objEmail = ObjCreate("CDO.Message")  
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'  
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""  
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress  
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress  
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then  
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then  
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")  
        For $x = 1 To $S_Files2Attach
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console  
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)  
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer  
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort  
    ;Authenticated SMTP
    If $s_Username <> "" Then  
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username  
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password  
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True  
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"  
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"  
        Case "Normal"  
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"  
        Case "Low"  
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"  
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send()
    If @error Then
        SetError(2)
		Return $oMyRet[1]
    EndIf
    $objEmail=""  
EndFunc

; Com Error Handler
Func MyComErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)  
    SetError(1); something to check for when this function returns
    Return
EndFunc
Member: LaMancha
LaMancha Sep 29, 2013 at 15:49:59 (UTC)
Goto Top
Hallo colinardo,

das Skript war ja eine Super-Überraschung! Habe es mal angepasst - und es läuft wie eine 1. Bleibt mir erstmal ein herzliches Dankeschön zu sagen. Und dann werde ich mich mal daran geben, zu verstehen, was da so passiert (vielleicht wird AutoIt ja mal ein Hobby von mir).

Viele Grüße - LaMancha
Member: colinardo
colinardo Sep 29, 2013 at 21:41:11 (UTC)
Goto Top
Achtung !! AutoIT kann süchtig machen face-smile Für Anfänger und Fortgeschrittene ist es beidermaßen gut geeignet.
AutoIT ist ein echtes Universalgenie, der große Vorteil liegt in der universellen Verwendung der kompilierten Dateien auf allen Windows-Betriebsystemen ohne irgendein Framework installieren zu müssen. Für Automatisierungsaufgaben perfekt geeignet und ein riesen Angebot an Funktionen jeglicher Art, selbst Benutzeroberflächen lassen sich damit problemlos realisieren.... Es gibt fast nichts was sich damit nicht realisieren ließe. Für das programmieren damit empfehle ich dir den Editor Scite.

Weiterhin viel Erfolg !

p.s. Bitte den Beitrag noch als gelöst markieren. Danke.

Grüße Uwe