Has anyone tried capturing the data from an IMDB page using PHP? Heres what i ahve so far...I've been trying to get a random movie from them using there scheme of movie datas (numbers range from 42068-310410 for movies from 1950-2002)
It doesn't seem to want to be able to read the page however...
<?
//**********************************************************
// Takes out all garabe from page and returns movie info
function check($url) {
$file = fopen($url, "r");
echo $url;
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (list ( , $line) = each ($file)) {
print "$line/n";
if (eregi("<TITLE>(.)</TITLE>", $line, $out)) {
$movie[title] = $out[1];
}
if (eregi('Genre</B😡.)<BR>', $line, $out)) {
$movie[genre] = $out[1];
}
if (eregi('<B>Date:</B>(.)<BR>', $line, $out)) {
$movie[date] = $out[1];
}
if (eregi('Runtime</B😡.)</TD>', $line, $out)) {
$movie[runtime] = $out[1];
}
}
fclose($file);
return movie;
}
//*******************************************************
//*************HTML STUFF**************************
?>
<head>
<title>Random Movie</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#333333">
<?
//*******************************************************
//*******************************************************
// Beginning of CODE
$url = "http://us.imdb.com/Title?0";
# An array with all the numbers
$movienum=range(42068,310410);
# Now shuffle it:
shuffle ($movienum);
#randomly choose a number withing the array
if ($movienum[1000] < 100000)
$url .= "0".$movienum[1000];
else
$url .= $movienum[1000];
$movieInfo = check($url);
print "Movie Info\n";
print $movieInfo[title];
print $movieInfo[year];
print $movieInfo[genre];
print $movieInfo[date];
?>
</body>
Any ideas would be appreciated!