Last active
August 29, 2015 13:56
-
-
Save thebabush/9271459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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