Hi,
in meinem LTE Tarif habe ich ein Datenvolumen. Über die Webseite Datennutzung lässt sich der aktuelle Verbrauch abfragen.
Hierzu habe ich ein Parsing-Script erstellt, welches die Werte in eine Variable schreibt.
Bitte verzeiht mir evtl. PHP Programmierfehler - ich bin froh, dass ich es so hinbekommen habe
Vielleicht hilft es dem ein oder anderen weiter.
Grüße
<?php
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
$curl = curl_init('http://pass.telekom.de');
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);
//print_r($page);
if(curl_errno($curl)) // check for execution errors
{
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$DOM = new DOMDocument;
//print_r($DOM);
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);
// ***********************************************
// Verbraucht ************************************
// ***********************************************
$verbraucht = $xpath->query('.//*[@id=\'content\']/div[1]/div/div[3]/span');
foreach ($verbraucht as $entry1) {
$output[] = $entry1->nodeValue;
}
//wegschneiden von unnötigen Zeichen
preg_match_all('!\d+!', $entry1->nodeValue, $matches);
$output_final = $matches[0][0] . '.' . $matches[0][1];
//schreibe in IPS Variable
SetValue(17875 /*[Fritzbox\LTE Details\LTE Verbrauch]*/, floatval($output_final));
// ***********************************************
// Kontingent ************************************
// ***********************************************
$kontingent = $xpath->query('.//*[@id=\'content\']/div[1]/div/div[3]');
foreach ($kontingent as $entry2) {
$output[] = $entry2->nodeValue;
}
print_r($output);
//wegschneiden von unnötigen Zeichen
preg_match_all('!\d+!', $entry2->nodeValue, $matches);
print_r($matches);
$output_final = $matches[0][2];
//schreibe in IPS Variable
SetValue(58848 /*[Fritzbox\LTE Details\LTE Kontingent]*/, floatval($output_final));
?>
LTEAuslesen.zip (15.4 KB)