Skip to content

Instantly share code, notes, and snippets.

@thebabush
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebabush/9271459 to your computer and use it in GitHub Desktop.
Save thebabush/9271459 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
"""
Find IMDB id of a given movie searching by title.
Works with all languages, not just English like
all the IMDB-python libs I've found on the internet.
"""
__author__ = '3mpty'
import urllib
import requests
from bs4 import BeautifulSoup
import re
IMDB_FIND_URL = "http://www.imdb.com/find?&s=all&%s"
def find_imdb_id_from_title(title):
url = IMDB_FIND_URL % urllib.urlencode({"q":title})
html = requests.request("GET", url).text
bs = BeautifulSoup(html)
href = bs.find("div", {"id":"main"}).find("td", {"class":"result_text"}).find("a").get("href")
imdb_id = re.match(".*/(tt\d+)/.*", href).group(1)
return imdb_id
if __name__ == "__main__":
print find_imdb_id_from_title("matrix (1999)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment