本文介绍了用php/js检索IMDB海报图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我只有电影页面的网址,有没有办法可以检索某部电影的 IMDB 主海报图像?(imdb.com)

Is there a way I can retrieve the IMDB main poster image for a certain film, if I just have the url to the film page? (imdb.com)

使用 php,也许是 js/jquery

Using php, perhaps js/jquery

推荐答案

是的,您可以检索 IMDB 电影海报.首先,您必须通过 curl 或 php 的 file_get_contents(); 连接 IMDB 网站;函数.另外,你应该解析HTML,你应该找到一个正则表达式,你必须得到图像的链接.我在下面的部分解释了简单的代码:

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);

?>

更新:我不会提供信息,有一个 IMDB API,从 API 获取图像 url 很简单.如果必须使用 API,则必须解析 json.下面有一个通过 API 从 IMDB 获取图像的简单代码代码段:

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);
?>

这篇关于用php/js检索IMDB海报图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 11:12