Moin,
also das Script ist nun fertig und es funktioniert! VIELEN DANK BAYARO!!!
Ich habe eine Instanz angelegt (HSV Tickets) unter der ich dann das Script erstellt habe. Durch das Script wird dann alles andere automatisch angelegt. Intervall für Aktualisierung und die zu durchsuchenden Ränge können individuell angepasst werden. Ich habe es noch etwas angepasst, da die HTML Box ursprünglich unter dem Script angelgt wurde. Ich finde es immer besser, wenn es auf der gleichen Ebene ist, da es sonst im WebFront doof aussieht. Die Tabelle ist natürlich nun im originalen HSV Blau (RAL 5002).
Screenshot
<?
/*********** HSV-Tickets auslesen **************/
/* Script v1.0 by Bayaro
/* Script v1.0.1 by lahlor :)
/*
/* https://www.symcon.de/forum/threads/30551-Hamburger-SV-TicketCrawler
/*
/* Skript 1x ausführen und Variable + Timer werden automatisch erstellt.
/* Die HTMLBox Variable dann einfach in euer WebFront verlinken.
/*
/*** KONFIGURATION *************************************************************/
$AktualisierungsIntervall = 15; // Tabelle wird alle X Minuten aktualisiert
$TabelleMitFarben = true; // Farbige Ausgabe der Ticket-Tabelle
//Array zum Definieren für welche Plätze die Tickets herausgefiltert werden sollen
$Platzwahl_AR[] = "22A";
$Platzwahl_AR[] = "23A";
$Platzwahl_AR[] = "24A";
$Platzwahl_AR[] = "25A";
$Platzwahl_AR[] = "26A";
$Platzwahl_AR[] = "27A";
/*******************************************************************************/
// Skript-Ausführungszeit erhöhen (je nachdem wie schnell die HSV Seite ist notwendig oder nicht)
ini_set("max_execution_time", 60);
// Timer setzen
IPS_SetScriptTimer($_IPS['SELF'], $AktualisierungsIntervall * 60);
// Spielbegegnungen - Ticket URLs ermitteln
$xpath1 = Webseite_DOM("https://ticketing.hsv.de/ticketboerse/default.php");
$content1 = $xpath1->query('.//td[@align="center"]/a/@href');
$i = 0;
foreach ($content1 as $entry01) {
$HSV_Ticket_AR[$i]["URL"] = $entry01->nodeValue;
$i++;
}
// Spielgegner ermitteln
$content2 = $xpath1->query('.//td[@align="left"]/span');
$i = 0;
foreach ($content2 as $entry02) {
$HSV_Ticket_AR[$i]["Gegner"] = $entry02->nodeValue;
$i++;
}
//Ticket URLs zu gewünschten Blöcken ermitteln
$x = 0;
for ($s=0; $s<count($HSV_Ticket_AR); $s++)
{
$xpathSpieltag = Webseite_DOM($HSV_Ticket_AR[$s]["URL"]);
$content = $xpathSpieltag->query('.//table[@id="spielserie"]/tbody/tr/td[1]');
foreach ($content as $entry) {
$Block = trim($entry->nodeValue);
if (array_search($Block, $Platzwahl_AR) !== false)
{
$contentBlockauswahl = $xpathSpieltag->query('.//table[@id="spielserie"]/tbody/tr/td[2]/a/@href');
foreach ($contentBlockauswahl as $entryX)
{
$BlockauswahlURL = $entryX->nodeValue;
preg_match("|(block=$Block)|", $BlockauswahlURL, $BlockMatch);
if (@array_key_exists("1", $BlockMatch) === true)
{
$HSV_Ticket_AR[$s]["TicketURLs"][$x]["Block"] = $Block;
$HSV_Ticket_AR[$s]["TicketURLs"][$x]["URL"] = $entryX->nodeValue;
$xpathBlock = Webseite_DOM($BlockauswahlURL);
//Anzahl verfügbarer Tickets ermitteln
$contentPlaetze = $xpathBlock->query('.//table[@id="spielserie"]/tbody/tr/td[1]');
$Platzcount = 0;
foreach ($contentPlaetze as $entryPlaetze)
{
$Platzcount++;
}
$HSV_Ticket_AR[$s]["TicketURLs"][$x]["AnzahlTickets"] = $Platzcount;
//Preise verfügbarer Tickets ermitteln
$contentPreise = $xpathBlock->query('.//table[@id="spielserie"]/tbody/tr/td[4]');
foreach ($contentPreise as $entryPreis)
{
$HSV_Ticket_AR[$s]["TicketURLs"][$x]["Preis"] = $entryPreis->nodeValue;
}
$x++;
}
}
}
}
}
//print_r($HSV_Ticket_AR);
// HTML CSS Style definieren (Tabelle, Schrift, Farben, ...)
if ($TabelleMitFarben == false) {
$HTML_CSS_Style = '';
}
else {
$HTML_CSS_Style = '<style type="text/css">
a:link {color:white; text-decoration:none}
a:visited {color:white; text-decoration:none}
a:active {color:white; text-decoration:none}
a:hover {color:blue; text-decoration:none}
.bt {border-collapse;border-spacing:0;}
.bt td {font-family:Arial, sans-serif;font-size:14px;padding:1px 10px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.bt th {font-family:Arial, sans-serif;font-size:14px;font-weigth:normal;padding:1px 10px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.bt .tb-match{font-size:12px;background-color:#000000;color:#FFFFFF;text-align:center}
.bt .tb-tickets{font-size:12px;background-color:#162E7B;color:#FFFFFF;text-align:center}
</style>';
}
// HTML Ausgabe generieren
$HTML = '<html>'.$HTML_CSS_Style;
$HTML .= '<center><table class="bt">';
for ($h=0; $h<count($HSV_Ticket_AR); $h++) {
$HTML .= '<tr><th class="tb-match">Hamburger SV</th><th class="tb-match">vs.</th><th class="tb-match">'.$HSV_Ticket_AR[$h]["Gegner"].'</th></tr>';
foreach ($HSV_Ticket_AR[$h]["TicketURLs"] as $TicketEntry)
{
$HTML .= '<tr><th class="tb-tickets">Block: '.$TicketEntry["Block"].'</th><th class="tb-tickets">Preis: '.$TicketEntry["Preis"].'</th><th class="tb-tickets"><a href='.$TicketEntry["URL"].' target="_blank">Verfügbare Tickets: '.$TicketEntry["AnzahlTickets"].'</a></th></tr>';
}
$HTML .= '<tr><th> </th><th> </th><th> </th></tr>';
}
$HTML .= '</table></center></html>';
echo $HTML;
// Variable erstellen, falls nicht vorhanden, und den Inhalt setzen
$Parent = IPS_GetParent($_IPS['SELF']);
$HTMLVariablenID = @IPS_GetVariableIDByName("Verfügbare Tickets", $Parent);
if ($HTMLVariablenID === false)
{
$HTMLBox_VarID = CreateVariableByName($_IPS['SELF'], "Verfügbare Tickets", 3, "~HTMLBox", "");
IPS_SetParent($HTMLBox_VarID, $Parent);
SetValue($HTMLBox_VarID, $HTML);
}
else
{
SetValue($HTMLVariablenID, $HTML);
}
function Webseite_DOM($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$page = curl_exec($curl);
if(curl_errno($curl)) // Error-Check
{
echo 'Error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$DOM = new DOMDocument;
libxml_use_internal_errors(true);
if (!$DOM->loadHTML($page))
{
$errors="";
foreach (libxml_get_errors() as $error) {
$errors.=$error->message."<br/>";
}
libxml_clear_errors();
print "libxml errors:<br>$errors";
return;
}
$xpath = new DOMXPath($DOM);
return $xpath;
}
function CreateVariableByName($ParentID, $VarName, $VarTyp, $VarProfile = "", $VarActionScript = "") {
$VarID = @IPS_GetVariableIDByName($VarName, $ParentID);
if($VarID === false) {
$VarID = IPS_CreateVariable($VarTyp);
IPS_SetParent($VarID, $ParentID);
IPS_SetName($VarID, $VarName);
IPS_SetInfo($VarID, "This variable was created by script #".$_IPS["SELF"]);
if($VarProfile !== "") {
IPS_SetVariableCustomProfile($VarID, $VarProfile);
}
if($VarActionScript !== "") {
IPS_SetVariableCustomAction($VarID, $VarActionScript);
}
}
return $VarID;
}
?>
Moin Moin,
ich habe mal von einem Bekannten ein nettes PHP Script bekommen, welches die Ticketbörse des HSV durchsucht und mir geziehlt noch verfügbare Stehplätze anbietet (mit direktem Link). Ich habe mir nun gedacht, ich baue das ganze unter IPS ein, da ich durch Zeitsteuerung das Script gezielt starten kann. Als Ergebnis erhalte ich einen HTML Code, den ich mir dann ja auch in das WebFront einbauen kann. Nun meine doch große Hürde - das Umbauen des Scripts. Ich scheiter gerade an der Ausgabe der Werte nicht als echo, sondern als nutzbare Variable, sodass ich diese in eine HTML Box schreiben lassen kann. Derzeit kann ich das Script manuell ausführen und das HTML Ergebnis via Copy&Paste in die Variable „HTML Box“ schreiben und es funktioniert. Vielleicht kann mir einer helfen, das ganze auch schöner umzusetzen. Ich würde schon einen Automatismus dahinter haben wollen
So schaut das eigenetliche Script aus
<?php include_once("simple_html_dom.php"); $target_url="https://ticketing.hsv.de/ticketboerse/default.php"; $html = new simple_html_dom(); $html->load_file($target_url); $count = 1; foreach($html->find('a') as $link) { if (strpos($link,'spielserie') !== false) { echo''; $already= false;
$target_url=$link->href;
$html1 = new simple_html_dom();
$html1->load_file($target_url);
$boolproof = false;
foreach($html1->find(‚a‘) as $link1)
{
if (strpos($link1,‚block=22A‘) !== false)
{
echo’’;
echo ‚22A‘ ;
$boolproof = true;
};
if (strpos($link1,‚block=23A‘) !== false)
{
echo’’;
echo ‚23A‘ ;
$boolproof = true;
};
if (strpos($link1,‚block=24A‘) !== false)
{
echo’’;
echo ‚24A‘;
$boolproof = true;
};
if (strpos($link1,‚block=25A‘) !== false)
{
echo’’;
echo ‚25A‘ ;
$boolproof = true;
};
if (strpos($link1,‚block=26A‘) !== false)
{
echo’’;
echo ‚26A‘ ;
$boolproof = true;
};
if (strpos($link1,‚block=27A‘) !== false)
{
echo’’;
echo ‚27A‘ ;
$boolproof = true;
};
if (strpos($link1,‚block=28A‘) !== false)
{
echo’’;
echo ‚28A‘ ;
$boolproof = true;
};
if (strpos($link1,‚block=22C‘) !== false)
{
echo’’;
echo ‚22C‘ ;
$boolproof = true;
};
}
if( $already == false)
{
foreach($html1->find(‚div‘) as $link2)
{
if(strpos($link2,‚Begegnung:‘) == true && strpos($link2,‚class=„main“‘) == false && strpos($link2,‚td class=„d_none“‘)== false
&& strpos($link2,‚class=„left“‘)== false)
{
echo’’;
$stringposition = strpos($link2, ‚<img src=‘);
$new_string = substr($link2, 0, $stringposition);
//$stringposition1 = strpos($link2, $new_string); $new_string2 = substr($link2, $stringposition+5, strlen($link2)); $stringposition2 = strpos($new_string2, '<img src='); $new_string1 = substr($new_string2, $stringposition2, strlen($new_string2)); $stringposition3 = strpos($new_string1, '/>'); $new_string4 = substr($new_string1, $stringposition3+2, strlen($new_string1));
$startString = strpos($new_string, '</b>'); $new_string = substr($new_string, $startString, strlen($new_string));
echo $new_string,' : ',$new_string4;
echo'</h1>'; $already = true; } } }
if($count==1&&$boolproof==true)
{
echo’’;
}
if($boolproof == false)
{
echo’Leider keine Stehplatzkarten vorhanden
’;
}
$boolproof = false;
$already = true;
$count++;
echo’’;
};
}
echo’’;
So das Ergebnis (HTML nicht filtern)
22A22C22C23A24A26A27A28AHamburger SV : Borussia Mönchengladbach
22A22C22C24A
Hamburger SV : FC Ingolstadt 04
22A22C22C23A26A27A28A
Hamburger SV : Hertha BSC
22A22C22C23A24A27A28A
Hamburger SV : TSG 1899 Hoffenheim
```
Dieses Ergebis würde ich gerne automatisch in eine Variable übergeben. Kann mir einer der Gurus helfen?
Ps.: Wenn man das ganze weiterspinnt, würde ich sogar noch eine Pushnotification auslösen, sodass ich sofort weiss, wann ein Ticket verfügbar ist. Ich komme nur leider mit dem eigentlichen Code nur bedingt zurecht, sodass es mir schwer fällt aus einem echo eine Variable zu erzeugen, die ich dann später in IPS verwenden kann.