How to Scrape IMDB Movies Data (Code & No Code)


2023-04-10 - 4 min read

Nicolae Rotaru
Nicolae Rotaru

Introduction

IMDB.com is one of the largest and most comprehensive movie databases, containing a vast collection of movie-related information such as movie titles, release dates, cast and crew details, ratings, and more.
If you're a movie enthusiast or data scientist looking to explore and analyze movie data, then IMDB is a great source of information.

However, manually collecting and analyzing this data can be a tedious and time-consuming task.
Fortunately, IMDB scraping offers a quick and efficient solution for automating this process.


In this article, you will read about the easiest way to scrape IMDB movies with Page2API.


You will find code examples for Ruby, Python, PHP, NodeJS, cURL for building an IMDB scraper and a No-Code solution that will help you import IMDB movies into Google Sheets.

Prerequisites

To start scraping IMDB movies, we will need the following things:


  • A Page2API account
  • An IMDB movies list that we are interested in.
    In our case, the list will be "Top 1000".

How to scrape IMDB Movies

First what we need is to open the "Top 1000" IMDB list.


The exact URL will be:

  
    https://www.imdb.com/search/title/?groups=top_1000


We will use this URL as the first parameter we need to start the scraping process.


The page that you see must look like the following one:

IMDB movies page From the IMDB movies page, we will scrape the following attributes from each movie:

  • Title
  • URL
  • Year
  • Genre
  • Votes
  • Rating
  • Runtime
  • Certificate

Now, let's define the selectors for each attribute.

  
    /* Parent: */
    .lister-item

    /* Title: */
    .lister-item-header

    /* URL: */
    .lister-item-header a

    /* Year: */
    .lister-item-year

    /* Genre: */
    .genre

    /* Votes: */
    [name=nv]

    /* Rating: */
    .ratings-imdb-rating

    /* Runtime: */
    .runtime

    /* Certificate: */
    .certificate

  

Let's handle the pagination.
There are two approaches that can help us scrape all the needed pages:

1. We can scrape the pages using the batch scraping feature
2. We can iterate through the pages by clicking on the Next page button

Now it's time to build the request that will scrape IMDB movies.

The following examples will show how to scrape 3 pages of movies from IMDB.com

If we decide to go with the batch scraping approach, our payload will look like:

  
    {
      "api_key": "YOUR_PAGE2API_KEY",
      "batch": {
        "urls": "https://www.imdb.com/search/title/?groups=top_1000&start=[1, 101, 50]",
        "concurrency": 1,
        "merge_results": true
      },
      "parse": {
        "movies": [
          {
            "title": ".lister-item-header >> text",
            "url": ".lister-item-header a >> href",
            "year": ".lister-item-year >> text",
            "genre": ".genre >> text",
            "votes": "[name=nv] >> text",
            "rating": ".ratings-imdb-rating >> data-value",
            "_parent": ".lister-item",
            "runtime": ".runtime >> text",
            "certificate": ".certificate >> text"
          }
        ]
      },
      "datacenter_proxy": "us"
    }
  

Code examples (batch scraping approach)

      
    require 'rest_client'
    require 'json'

    api_url = "https://www.page2api.com/api/v1/scrape"
    payload = {
      api_key: "YOUR_PAGE2API_KEY",
      batch: {
        urls: "https://www.imdb.com/search/title/?groups=top_1000&start=[1, 101, 50]",
        concurrency: 1,
        merge_results: true
      },
      parse: {
        movies: [
          {
            title: ".lister-item-header >> text",
            url: ".lister-item-header a >> href",
            year: ".lister-item-year >> text",
            genre: ".genre >> text",
            votes: "[name=nv] >> text",
            rating: ".ratings-imdb-rating >> data-value",
            _parent: ".lister-item",
            runtime: ".runtime >> text",
            certificate: ".certificate >> text"
          }
        ]
      },
      datacenter_proxy: "us"
    }

    response = RestClient::Request.execute(
      method: :post,
      payload: payload.to_json,
      url: api_url,
      headers: { "Content-type" => "application/json" },
    ).body

    result = JSON.parse(response)

    puts(result)
      
    

Let's take a look at the Next page approach.


Note: the 'Next page' approach described below is for demonstrational purposes only.
We strongly recommend you use the 'Batch' approach whenever possible since it's faster and more reliable.


With this approach, to go to the next page, we must click on the next page button if it's present on the page:

  
    document.querySelector(".next-page")?.click()
  

IMDB next page active

The scraping will continue while the next page button is present on the page, and stop if it disappears.
The stop condition for the scraper will be the following javascript snippet:


  
    document.querySelector(".next-page") === null
  

If we decide to go with the next page approach, our payload will look like:

  
    {
      "api_key": "YOUR_PAGE2API_KEY",
      "url": "https://www.imdb.com/search/title/?groups=top_1000",
      "real_browser": true,
      "merge_loops": true,
      "scenario": [
        {
          "loop": [
            { "wait_for": ".lister-item" },
            { "execute": "parse" },
            { "execute_js": "document.querySelector('.next-page')?.click()" }
          ],
          "stop_condition": "document.querySelector('.next-page') === null",
          "iterations": 3
        }
      ],
      "parse": {
        "movies": [
          {
            "title": ".lister-item-header >> text",
            "url": ".lister-item-header a >> href",
            "year": ".lister-item-year >> text",
            "genre": ".genre >> text",
            "votes": "[name=nv] >> text",
            "rating": ".ratings-imdb-rating >> data-value",
            "_parent": ".lister-item",
            "runtime": ".runtime >> text",
            "certificate": ".certificate >> text"
          }
        ]
      },
      "datacenter_proxy": "us"
    }
  

Code examples (next button approach)

      
    require 'rest_client'
    require 'json'

    api_url = "https://www.page2api.com/api/v1/scrape"
    payload = {
      api_key: "YOUR_PAGE2API_KEY",
      url: "https://www.imdb.com/search/title/?groups=top_1000",
      real_browser: true,
      merge_loops: true,
      scenario: [
        {
          loop: [
            { wait_for: ".lister-item" },
            { execute: "parse" },
            { execute_js: "document.querySelector('.next-page')?.click()" }
          ],
          stop_condition: "document.querySelector('.next-page') === null",
          iterations: 3
        }
      ],
      parse: {
        movies: [
          {
            title: ".lister-item-header >> text",
            url: ".lister-item-header a >> href",
            year: ".lister-item-year >> text",
            genre: ".genre >> text",
            votes: "[name=nv] >> text",
            rating: ".ratings-imdb-rating >> data-value",
            _parent: ".lister-item",
            runtime: ".runtime >> text",
            certificate: ".certificate >> text"
          }
        ]
      },
      datacenter_proxy: "us"
    }

    response = RestClient::Request.execute(
      method: :post,
      payload: payload.to_json,
      url: api_url,
      headers: { "Content-type" => "application/json" },
    ).body

    result = JSON.parse(response)

    puts(result)
      
    

The result

  
    {
      "result": {
        "movies": [
          {
            "title": "1. John Wick: Chapter 4 (2023)",
            "url": "https://www.imdb.com/title/tt10366206/?ref_=adv_li_tt",
            "year": "(2023)",
            "genre": "Action, Crime, Thriller",
            "votes": "103,371",
            "rating": "8.3",
            "runtime": "169 min",
            "certificate": "R"
          },
          {
            "title": "2. Avatar: The Way of Water (2022)",
            "url": "https://www.imdb.com/title/tt1630029/?ref_=adv_li_tt",
            "year": "(2022)",
            "genre": "Action, Adventure, Fantasy",
            "votes": "347,882",
            "rating": "7.7",
            "runtime": "192 min",
            "certificate": "PG-13"
          }, ...
        ]
      }, ...
    }
  

How to export IMDB movies to Google Sheets

In order to be able to export the IMDB movies to a Google Spreadsheet we will need to slightly modify our request to receive the data in CSV format instead of JSON.

According to the documentation, we need to add the following parameters to our payload:
  
    "raw": {
      "key": "movies", "format": "csv"
    }
  

Now our payload will look like:

{ "api_key": "YOUR_PAGE2API_KEY", "batch": { "urls": "https://www.imdb.com/search/title/?groups=top_1000&start=[1, 101, 50]", "concurrency": 1, "merge_results": true }, "parse": { "movies": [ { "title": ".lister-item-header >> text", "url": ".lister-item-header a >> href", "year": ".lister-item-year >> text", "genre": ".genre >> text", "votes": "[name=nv] >> text", "rating": ".ratings-imdb-rating >> data-value", "_parent": ".lister-item", "runtime": ".runtime >> text", "certificate": ".certificate >> text" } ] }, "datacenter_proxy": "us", "raw": { "key": "movies", "format": "csv" } }

Please note that the batch URLs are defined explicitly to make it simpler to edit the payload.


Now, edit the payload above if needed, and press Encode →

The URL with encoded payload will be:


  Press 'Encode'

Note: If you are reading this article being logged in - you can copy the link above since it will already have your api_key in the encoded payload.

The final part is adding the IMPORTDATA function, and we are ready to import our IMDB movies into a Google Spreadsheet.
  Press 'Encode'

The result must look like the following one:

IMDB movies import to Google Sheets

Conclusion

In conclusion, web scraping is an efficient and powerful tool for collecting and analyzing data from websites.
IMDB.com provides a rich source of movie-related information, and with Page2API, you can easily and quickly scrape this data for analysis.

In this blog post, we covered a step-by-step guide on how to scrape IMDB movie data using Page2API.

We explored various techniques for collecting and parsing data from IMDB, including batch scraping, handling pagination, and extracting specific elements like movie titles and ratings, and more.

With the knowledge and techniques covered in this blog post, you can now start exploring IMDB's vast collection of movie data and use it for a variety of applications, from research and analysis to building your own movie recommendation engine.

You might also like

Nicolae Rotaru
Nicolae Rotaru
2023-01-07 - 5 min read

How to Scrape Youtube Data: Video and Channel Details (Code & No Code)

In this article, you will find an easy way to scrape Youtube with Page2API using one of your favorite programming languages or a no-code solution that will import Youtube channel videos to Google Sheets

Nicolae Rotaru
Nicolae Rotaru
2022-11-21 - 4 min read

How to Scrape Instagram: Account Data, Posts, Images (Code & No Code)

In this article, you will find an easy way to scrape Instagram with Page2API using one of your favorite programming languages or a no-code solution that will import Instagram posts to Google Sheets

Nicolae Rotaru
Nicolae Rotaru
2022-09-29 - 4 min read

How to Scrape Yellow Pages: Business Names, Addresses, Phone Numbers (Code & No Code)

In this article, you will find an easy way to scrape Yellow Pages with Page2API using one of your favorite programming languages or a no-code solution that will import the data to Google Sheets

What customers are saying

Superb support
Superb, reliable support, even out of hours, patient and polite plus educational.
October 21, 2023
Very effective and trustworthy
Very effective and trustworthy!
I had some challenges which were addressed right away.
October 12, 2023
Page2API is without fail my favorite scraping API
Not only does Page2API work without fail constantly, but their customer support team is on a new level.
If i ever have issues integrating or have errors in my code they've always been responsive almost instantly and helped fix any errors.
I've never seen customer service like this anywhere, so massive thanks to the Page2API team.
July 14, 2023
Amazing product and support!
I have tried a lot of different scraping solutions and Page2Api is definitely the best one. It's very developer-friendly and Nick is extremely innovative in coming up with new ideas to solve problems.
The support is unreal as well.
I have sent Nick a request that I have trouble scraping and he's helped me fix all of them. Can highly recommend.
April 13, 2023
This API is amazing and the support was GREAT
This API is amazing and I am very excited to keep using it.
I'm writing this review because I was stumped on a very hard scrape for youtube transcripts, I brought my issue to support and in no time they had written what looks like a very tailored and complicated API call for me, I tested it and it worked perfect! Great great support.
April 19, 2023
Excellent service, super technical support!
I have been looking for such a quality for a long time, I have never met such an individual approach to clients.
Everything is at the highest level!
Nick very quickly helped to deal with all my questions, I am very grateful to him!
Recommend!
February 08, 2023
Fantastic Product and Customer Service
I'm a no-code guy trying to hack it in an API world... so I was pretty apprehensive about what I would be getting into with this.
I'm please to say that the customer service is so fantastic that they got me a solution in under 30 seconds that worked instantly in my application.
They did a great job and it works exactly as advertised.
Highly recommend them!
March 24, 2023
Surprisingly great service and support
I have certainly not come across any other internet initiative in the internet world that provides such good technical support and tries to help even if they are not related to them.
I will take as an example the approach of page2api to the customer in the startups I have founded.
February 16, 2023
Perfect for webcrapping javascript generated webpages
Page2API is perfect to be use from bubble or any other nocode tool.
It works submitting forms, scrapping info, and loading javascript generated content in webpages.
January 22, 2023
Best scraping service - tried them all
Hands down the best scraping service there is for a no-coder (...and I've tried them all).
Fast, easy to use, great documentation and stellar support.
Wish I'd found this months and months ago of waisting time at others. Highly recommend!
May 05, 2023
The best web scraper API for Bubble apps
Having tried several web scraper APIs I have found that Page2API is the best web scraper API for integrating with the Bubble API connector.
If you're a Bubble app developer Page2API is the web scraper you've been looking for!
November 30, 2022
Customer service is WORLD CLASS
Nick is serious about his business -- super knowledgeable and helpful whenever we have the slightest problem.
Honestly, the best customer service of any SaaS I've had the pleasure of working with.
10/10.
December 02, 2022
It's a perfect product
This team has a very high sense of responsibility for the product.
They let me know the part I don't know so kindly.
I didn't feel any discomfort when I used it in Korea
June 12, 2023
Highly professional support!
Amazing quick support!
But more than that, an actual relevant and pro help which solved my issue.
April 19, 2023
Incredible
Nick was incredible.
He helped me so much.
Need it for a research project and I highly highly recommend this service.
December 21, 2022
Great product, great support
I was searching for a scraping tool which fits to different types of needs and found Page2API.
The support is amazing and the product, too!
We will use Page2API also for our agency clients now.
Thank you for this great tool!
March 07, 2023
Really good provider for web-scraping…
Really good provider for web-scraping services, their customer service is top notch!
January 25, 2023
Great service with absolutely…
Great service with absolutely outstanding support
December 01, 2022

Ready to Scrape the Web like a PRO?

1000 free API calls.
Based on all requests made in the last 30 days. 99.85% success rate.
No-code-friendly.
Trustpilot stars 4.6