Retrieve IMDB Poster Picture With Php/js
Solution 1:
Yes, you can retreive IMDB movie posters.Firstly, You must connect IMDB website by the curl or php's file_get_contents(); function.Also, you should parse HTML and you should find a regular expression and you must get the link of image.I explained simple of code in the following segment:
<?php
$URL = "There will be movie detail page";
$DetailPage = file_get_content($URL);
$ImageSource = preg_match("/ regex will be here /i",$DetailPage,$ImageSource); //Here you must find a image from source.
$Image_Tag = $ImageSource[0]; // it's a image tag from IMDB you should get inside of src=""
...
...
$ImageLink = ...
$PosterImage = file_get_contents($ImageLink);
file_put_contents("your_image_folder/your_posters_name.jpg", $PosterImage);
?>
UPDATED: I would not information about, there is a IMDB API and it's simple and easy to getting image url from API.You have to parse json if you have to use API.There is a simple code for getting image from IMDB by API in the following segment of code:
<?php
$URL = "http://www.imdbapi.com/?i=&t=inception";
$Page = file_get_contents($URL);
$MovieInformations = json_decode($Page);
$Poster = $MovieInformations["Poster"];
$GetImage = file_get_contents($Poster);
file_put_contents("your_image_folder/your_posters_name.jpg", $GetImage);
?>
Solution 2:
You can use php scripting to get the data from another site follow the method below
1) Add file 'simple_html_dom.php' available on internet
set_time_limit(o); include_once('simple_html_dom.php');
2) Define the function scraping_IMDB and saveImg :
function scraping_IMDB($url)
{
$html = file_get_html($url);
$ret['path'] = '';
foreach($html->find('div[class="post"] img[class="wp-post-image"]') as $e)
{
$ret['path'] = $e->src;
}
$html->clear();
unset($html);
return $ret;
}
function saveImg($url)
{
$i = file_get_contents($url);
$name = end(explode('/',rtrim($url,'/')));
$f = fopen('photos/'.$name,'w+');
fwrite($f,$i);
fclose($f);
}
3) call the finction with the url:
$ret = scraping_IMDB('http://imdb.com');
Solution 3:
Thanks for inputs. I found, the easiest and simplest way for me is to use this:
function getImage($imdbid)
{
$source = file_get_contents('http://www.imdbapi.com/?i='.$imdbid);
$decode = json_decode($source, true);
return $decode['Poster'];
}
First, extract the movie id from the url, and then use getImage($theidfromtheurl). Voila
Post a Comment for "Retrieve IMDB Poster Picture With Php/js"