Given an IMDB movie id, how do I programmatically

2020-02-02 09:47发布

movie id tt0438097 can be found at http://www.imdb.com/title/tt0438097/

What's the url for its poster image?

标签: imdb
16条回答
在下西门庆
2楼-- · 2020-02-02 10:09

Check out http://www.imdbapi.com/, It returns Poster url in string.

For example, check http://www.imdbapi.com/?i=&t=inception and you'll get the poster address: Poster":"http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1._SX320.jpg"

Update: Seems like the site owner had some arguments with IMDB legal staff. As mentioned in the original site, new site's address is http://www.omdbapi.com/

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-02-02 10:10

The URL is a random string as far as I can tell.

It can still be easily retrieved. It is the only img inside the anchor named poster.

So, if you are reading the source, simply search for <a name="poster" and it will be the text following the first src=" from there.

However, you will need to keep the screen scraping code updated because that will probably change.


You should also be aware that the images are copyrighted, so be careful to only use the image under a good "fair use" rationale.

查看更多
乱世女痞
4楼-- · 2020-02-02 10:13
$Movies = Get-ChildItem -path "Z:\MOVIES\COMEDY" | Where-Object {$_.Extension -eq ".avi" -or $_.Extension -eq ".mp4" -or $_.Extension -eq ".mkv" -or $_.Extension -eq<br>  <br>".flv" -or $_.Extension -eq ".xvid" -or $_.Extension -eq ".divx"} | Select-Object Name, FullName | Sort Name <br>
#Grab all the extension types and filter the ones I ONLY want <br>
<br>
$COMEDY = ForEach($Movie in $Movies) <br>
{<br>
        $Title = $($Movie.Name)<br>
        #Remove the file extension<br>
        $Title = $Title.split('.')[0] <br>       
<br>
        #Changing the case to all lower <br>       
        $Title = $Title.ToLower()<br>
<br>
        #Replace a space w/ %20 for the search structure<br>
        $searchTitle = $Title.Replace(' ','%20')       <br>
<br>
        #Fetching search results<br>
        $moviesearch = Invoke-WebRequest "http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"<br>
         <br>
        #Moving html elements into variable<br>
        $titleclassarray = $moviesearch.AllElements | where Class -eq 'title' | select -First 1<br>
<br>
        #Checking if result contains movies<br>
        try<br><br>
        {
            $titleclass = $titleclassarray[0]<br>
        }<br>
        catch<br>
        {<br>
            Write-Warning "No movie found matching that title http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"<br>
        }      <br>
                   <br>
        #Parcing HTML for movie link<br>
        $regex = "<\s*a\s*[^>]*?href\s*=\s*[`"']*([^`"'>]+)[^>]*?>"<br>
        $linksFound = [Regex]::Matches($titleclass.innerHTML, $regex, "IgnoreCase")<br>
         <br><br>

        #Fetching the first result from <br>
        $titlelink = New-Object System.Collections.ArrayList<br>
        foreach($link in $linksFound)<br>
        {<br>
            $trimmedlink = $link.Groups[1].Value.Trim()<br>
            if ($trimmedlink.Contains('/title/'))<br>
            {<br>
                [void] $titlelink.Add($trimmedlink)<br>
            }<br>
        }<br>
        #Fetching movie page<br>
        $movieURL = "http://www.imdb.com$($titlelink[0])"<br>
        <br>
        #Grabbing the URL for the Movie Poster<br>
        $MoviePoster = ((Invoke-WebRequest –Uri $movieURL).Images | Where-Object {$_.title -like "$Title Poster"} | Where src -like "http:*").src  <br> 
<br>
        $MyVariable = "<a href=" + '"' + $($Movie.FullName) + '"' + " " + "title='$Title'" + ">"<br>
        $ImgLocation = "<img src=" + '"' + "$MoviePoster" + '"' + "width=" + '"' + "225" + '"' + "height=" + '"' + "275" + '"' + "border=" + '"' + "0" + '"' + "alt=" +<br> '"' + $Title + '"' + "></a>" + "&nbsp;" + "&nbsp;" + "&nbsp;"+ "&nbsp;" + "&nbsp;" + "&nbsp;"+ "&nbsp;" + "&nbsp;" + "&nbsp;"<br>
        <br>
        Write-Output $MyVariable, $ImgLocation<br>
       <br>
    }$COMEDY | Out-File z:\db\COMEDY.htm  <br>
<br>
    $after = Get-Content z:\db\COMEDY.htm <br>
<br>
    #adding a back button to the Index <br>
    $before = Get-Content z:\db\before.txt<br>
<br>
    #adding the back button prior to the poster images content<br>
    Set-Content z:\db\COMEDY.htm –value $before, $after<br>
查看更多
啃猪蹄的小仙女
5楼-- · 2020-02-02 10:13

Now a days, all modern browser have "Inspect" section:

100% Correct for Google Chrome only:

  1. Take your cursor on image.
  2. Right click on it, select "Inspect Element".
  3. In the window appear, under Elements tab you will find the highlighted text as
  4. Just click on it.
  5. In the Resource tab, right click on image.
  6. Select "Copy image URL" option.

Try to paste it any where as URL in any browser, you will only get the image.

查看更多
混吃等死
6楼-- · 2020-02-02 10:18

Here is my program to generate human readable html summary page for movie companies found on imdb page. Change the initial url to your liking and it generates a html file where you can see title, summary, score and thumbnail.

npm install -g phantomjs

Here is the script, save it to imdb.js

var system = require('system');

var page = require('webpage').create();
page.open('http://www.imdb.com/company/co0026841/?ref_=fn_al_co_1', function() {
  console.log('Fetching movies list');
  var movies = page.evaluate(function() {
    var list = $('ol li');
    var json = []
    $.each(list, function(index, listItem) {
      var link = $(listItem).find('a');
      json.push({link: 'http://www.imdb.com' + link.attr('href')});
    });
    return json;
  });
  page.close();

  console.log('Found ' + movies.length + ' movies');

  fetchMovies(movies, 0);
});

function fetchMovies(movies, index) {
  if (index == movies.length) {
    console.log('Done');

    console.log('Generating HTML');
    genHtml(movies);

    phantom.exit();
    return;
  }
  var movie = movies[index];

  console.log('Requesting data for '+ movie.link);

  var page = require('webpage').create();
  page.open(movie.link, function() {
    console.log('Fetching data');
    var data = page.evaluate(function() {
      var title = $('.title_wrapper h1').text().trim();
      var summary = $('.summary_text').text().trim();
      var rating = $('.ratingValue strong').attr('title');
      var thumb = $('.poster img').attr('src');

      if (title == undefined || thumb == undefined) {
        return null;
      }
      return { title: title, summary: summary, rating: rating, thumb: thumb };
    });

    if (data != null) {
      movie.title = data.title;
      movie.summary = data.summary;
      movie.rating = data.rating;
      movie.thumb = data.thumb;
      console.log(movie.title)
      console.log('Request complete');
    } else {
      movies.slice(index, 1);
      index -= 1;
      console.log('No data found');
    }
    page.close();
    fetchMovies(movies, index + 1);
  });
}

function genHtml(movies) {
  var fs = require('fs');

  var path = 'movies.html';
  var content = Array();

  movies.forEach(function(movie) {
    var section = '';

    section += '<div>';
    section += '<h3>'+movie.title+'</h3>';
    section += '<p>'+movie.summary+'</p>';
    section += '<p>'+movie.rating+'</p>';
    section += '<img src="'+movie.thumb+'">';
    section += '</div>';

    content.push(section);
  });

  var html = '<html>'+content.join('\n')+'</html>';

  fs.write(path, html, 'w');
}

And run it like so

phantomjs imdb.js
查看更多
Ridiculous、
7楼-- · 2020-02-02 10:19

You can use imdb-cli tool to download movie's poster, e.g.

omdbtool -t "Ice Age: The Meltdown" | wget `sed -n '/^poster/{n;p;}'`
查看更多
登录 后发表回答