To obtain all Johnny Depp movies from IMDb and filter them by rating in Python, we can use web scraping techniques along with the IMDb website.
First, we need to import the necessary libraries such as requests and BeautifulSoup. We then need to send a GET request to IMDb's search page with Johnny Depp's name as the query parameter. We then parse the HTML content of the search page using BeautifulSoup to obtain the list of search results which contains all Johnny Depp movies.
Next, we need to filter out all irrelevant search results that are not movies. We can do this by checking the result type for each search result.
Finally, we can sort the list of Johnny Depp movies by ratings and print out the top-rated movies. Here is an example code snippet that achieves this:
main.py1370 chars40 lines
In this example code snippet, we define two functions:
get_johnny_depp_movies
: sends a GET request to IMDb's search page for Johnny Depp and obtains the list of all search results that are movies.filter_by_rating
: filters out all movies with a rating less than the given min_rating
parameter.We then call these two functions to obtain and filter the list of Johnny Depp movies. We then sort the filtered movies in descending order based on their rating and print out the top-rated movies along with their ratings.
gistlibby LogSnag