Javascript 使用php/js检索IMDB海报图片
如果我只有电影页面的url,有没有办法检索某部电影的IMDB主海报图像?(imdb.com)Javascript 使用php/js检索IMDB海报图片,javascript,php,jquery,url,Javascript,Php,Jquery,Url,如果我只有电影页面的url,有没有办法检索某部电影的IMDB主海报图像?(imdb.com) 使用php,也许js/jquery是的,您可以检索IMDB电影海报。首先,您必须通过curl或php的文件_get_contents()连接IMDB网站;函数。此外,您应该解析HTML,并找到正则表达式,您必须获得图像链接。我在以下部分中解释了简单的代码: <?php $URL = "There will be movie detail page"; $DetailPage =
使用php,也许js/jquery是的,您可以检索IMDB电影海报。首先,您必须通过curl或php的文件_get_contents()连接IMDB网站;函数。此外,您应该解析HTML,并找到正则表达式,您必须获得图像链接。我在以下部分中解释了简单的代码:
<?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);
?>
您可以使用php脚本从另一个站点获取数据,方法如下 1) 添加internet上可用的文件“simple_html_dom.php” 设置时间限制(o); 包括一次('simple_html_dom.php') 2) 定义函数scraping_IMDB和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) 使用url调用finction:
$ret = scraping_IMDB('http://imdb.com');
谢谢你的意见。
我发现,对我来说,最简单的方法就是使用:
function getImage($imdbid)
{
$source = file_get_contents('http://www.imdbapi.com/?i='.$imdbid);
$decode = json_decode($source, true);
return $decode['Poster'];
}
首先,从url中提取电影id,然后使用getImage($theidfromtheurl)。
瞧PHP,并使用框架刮取页面。不要使用regexp。是的,有。如果您对较小的版本感到满意,则页面上的图像始终具有ID=“primary poster”Small/simple就好了。这不是为了好玩的东西。你能帮我弄清楚我该怎么做才能做得更好吗?;)也许这就是我需要的,但它使用标题而不是url看起来很有希望。但是我已经完全不习惯使用正则表达式了。。你能帮我设置一下吗是的。我可以,但在链接中有一个更简单的方法,你可以在评论中分享。我分享了关于它们的新代码。我认为这比第一个对你来说更容易。
function getImage($imdbid)
{
$source = file_get_contents('http://www.imdbapi.com/?i='.$imdbid);
$decode = json_decode($source, true);
return $decode['Poster'];
}