Web scraping using transients

Try something like this, which would save in transient for 12 hours. Let me know if anything does not make sense.

<?php
$value = get_transient( 'value' );
if ( false === $value ) {
  $output = "";
  $html = file_get_contents('http://www.example.com');       
  $doc = new DOMDocument();

  libxml_use_internal_errors(TRUE); // disable libxml errors

  if(!empty($html)) {

    $doc->loadHTML($html);
    libxml_clear_errors();

    $xpath = new DOMXPath($doc);

    // Get only the content needed
    $termine = $xpath->query('//ul[@class="artistEvents"]/li');            

    if ($termine->length > 0) {
      foreach ($termine as $termin) { 

        $date = $xpath->query("div[@class="left"]/strong", $termin);
        $location = $xpath->query("div[contains(@class,'right')]", $termin);

        $output .= '<tr>';

        // Date     
        if ($date->length > 0) {
          $date = substr($date->item(0)->nodeValue, 3, 10);
          $date = strftime("%d.%m.%Y", strtotime($date));
          $output .= '<td class="live-date">' . $date . '</td>';
        }

        // Location
        if ($location->length > 0) {
          $location = substr($location->item(0)->nodeValue, 14);
          $location = utf8_decode($location);
          $output .= '<td class="live-location">' . $location . '</td>';
        }

        $output .= '</tr>';
      }
    }
    else {
      $output .= '<p>No dates available.</p>';
    }
  }
  $value = $output;
  set_transient( 'value', $value, 12 * HOUR_IN_SECONDS );

}
echo $value;
?>