Given an IMDB movie id, how do I programmatically get its poster image?

前端 未结 17 782
礼貌的吻别
礼貌的吻别 2020-12-08 03:17

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

What\'s the url for its poster image?

17条回答
  •  自闭症患者
    2020-12-08 03:55

    $Movies = Get-ChildItem -path "Z:\MOVIES\COMEDY" | Where-Object {$_.Extension -eq ".avi" -or $_.Extension -eq ".mp4" -or $_.Extension -eq ".mkv" -or $_.Extension -eq

    ".flv" -or $_.Extension -eq ".xvid" -or $_.Extension -eq ".divx"} | Select-Object Name, FullName | Sort Name
    #Grab all the extension types and filter the ones I ONLY want

    $COMEDY = ForEach($Movie in $Movies)
    {
    $Title = $($Movie.Name)
    #Remove the file extension
    $Title = $Title.split('.')[0]

    #Changing the case to all lower
    $Title = $Title.ToLower()

    #Replace a space w/ %20 for the search structure
    $searchTitle = $Title.Replace(' ','%20')

    #Fetching search results
    $moviesearch = Invoke-WebRequest "http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"

    #Moving html elements into variable
    $titleclassarray = $moviesearch.AllElements | where Class -eq 'title' | select -First 1

    #Checking if result contains movies
    try

    { $titleclass = $titleclassarray[0]
    }
    catch
    {
    Write-Warning "No movie found matching that title http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"
    }

    #Parcing HTML for movie link
    $regex = "<\s*a\s*[^>]*?href\s*=\s*[`"']*([^`"'>]+)[^>]*?>"
    $linksFound = [Regex]::Matches($titleclass.innerHTML, $regex, "IgnoreCase")


    #Fetching the first result from
    $titlelink = New-Object System.Collections.ArrayList
    foreach($link in $linksFound)
    {
    $trimmedlink = $link.Groups[1].Value.Trim()
    if ($trimmedlink.Contains('/title/'))
    {
    [void] $titlelink.Add($trimmedlink)
    }
    }
    #Fetching movie page
    $movieURL = "http://www.imdb.com$($titlelink[0])"

    #Grabbing the URL for the Movie Poster
    $MoviePoster = ((Invoke-WebRequest –Uri $movieURL).Images | Where-Object {$_.title -like "$Title Poster"} | Where src -like "http:*").src

    $MyVariable = ""
    $ImgLocation = "
    " + " " + " " + " "+ " " + " " + " "+ " " + " " + " "

    Write-Output $MyVariable, $ImgLocation

    }$COMEDY | Out-File z:\db\COMEDY.htm

    $after = Get-Content z:\db\COMEDY.htm

    #adding a back button to the Index
    $before = Get-Content z:\db\before.txt

    #adding the back button prior to the poster images content
    Set-Content z:\db\COMEDY.htm –value $before, $after

提交回复
热议问题