Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', true);
- define('CACHE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cache');
- function download_from_internet($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_HTTPGET, true);
- // curl_setopt($ch, CURLOPT_COOKIEFILE, CACHE_DIR . DIRECTORY_SEPARATOR . 'cookies.txt');
- // curl_setopt($ch, CURLOPT_COOKIEJAR, CACHE_DIR . DIRECTORY_SEPARATOR . 'cookies.txt');
- // curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
- $source = curl_exec ($ch);
- return $source;
- }
- function download_with_cache($url, $ttl = 86400)
- {
- $cache_file = CACHE_DIR . DIRECTORY_SEPARATOR . strtr($url, ':/?|#', '.....').'xxx';
- if (!is_dir(CACHE_DIR)) {
- mkdir(CACHE_DIR, 0755);
- }
- // these lines will check and create a cache directory if there is none
- if (
- is_file($cache_file)
- &&
- filemtime($cache_file) > time() - $ttl)
- {
- $contents = file_get_contents($cache_file);
- } else { //
- $contents = download_from_internet($url);
- file_put_contents($cache_file, $contents);
- }
- return $contents;
- }
- $url = "http://www.imdb.com/genre/";
- $contents = download_with_cache($url);
- header('Content-type: text/plain');
- $contents = download_with_cache($url);
- $contents = substr($contents, strpos($contents, '<table class="genre-table"'));//goes to imdb and targets the table
- $contents = substr($contents, 0, strpos($contents, '</table'));
- $contents = strip_tags($contents, '<a>');
- foreach (explode("\n", $contents) as $line) {
- if (strpos($line, '»') !== false) {
- echo "'" , trim(str_replace('»', '', strip_tags($line))) , "',\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement