DEV Community

Cover image for How to scrape Douban movie ratings and star distributions with Python and pandas
Norbert Sobala
Norbert Sobala

Posted on

How to scrape Douban movie ratings and star distributions with Python and pandas

Douban (豆瓣) is where Chinese audiences rate films, series, books and music. If you work on a film release, a translation deal or a localisation project for China, the Douban score is usually the first number someone asks about. The site has no public API for outsiders, and copying scores by hand from a Chinese interface gets old after the third title.

This walkthrough uses the Douban Scraper on Apify. I ran it once on the Movie Top 250 chart, limited to the first 40 titles, with comments and reviews switched off. The run took about 150 seconds and returned 40 records. Every number below comes from that dataset.

Douban Scraper output: Movie Top 250, first 40 titles

What data you get

The actor writes three record types to one dataset. You can tell them apart by recordType.

Field Type Example from my run
recordType string subject
subjectType string movie (also tv, book, music)
title / originalTitle string 肖申克的救赎 / The Shawshank Redemption
year number 1994
rating number, 0 to 10 9.7
ratingCount number 3,370,033
ratingDistributionPercent object {"5": 85.4, "4": 13, "3": 1.4, "2": 0.1, "1": 0.1}
genreRanks list crime film, better than 99%
genres, countries, languages lists 剧情, 犯罪 / 美国 / 英语
directors, actors lists credited cast and crew
durations list 142分钟
commentCount, reviewCount numbers 673,114 / 15,088
doneCount, wishCount numbers watched 5,802,665 / want to watch 523,176
chart, chartRank string, number movie_top250, 1
tags, intro, coverUrl, url mixed tags, synopsis, poster, page link

If you turn on comments you also get comment records (short comment text, 1 to 5 stars, watched or wishlist status, helpful votes, date). Long reviews come as review records with title, rating, votes and optionally the full text. The actor does not save commenter names, user IDs, avatars or IP locations, only the content and the rating.

Values stay in Chinese because that is how Douban stores them. Four of my 40 titles had no originalTitle at all, all of them Chinese-language films such as 霸王别姬 and 活着, so plan for nulls there.

Main input options

You can mix three ways of picking titles in one run:

  • subjectUrls: Douban pages such as https://movie.douban.com/subject/1292052/. Short forms like movie:1292052 or book:2567698 also work.
  • searchQueries with searchType (movie, book or music) and maxSearchResults per query. Chinese and English titles both work. Douban search is fuzzy, so check the top hit before trusting it.
  • charts with maxChartItems: movie_top250, movie_showing, movie_real_time_hotest, movie_weekly_best, tv_hot, tv_real_time_hotest, tv_chinese_best_weekly, book_top250, book_bestseller, music_single.

Then decide on the extras. includeComments and maxCommentsPerSubject (up to about 150 per title, most helpful first) control short comments. includeReviews, maxReviewsPerSubject (about 50 without login) and fullReviewText control long reviews. Comments are on by default, so switch them off if you only want scores, as I did.

Douban Scraper input schema

Option 1: no code

  1. Open the Douban Scraper page and click Try for free.
  2. In Douban charts, pick Movies – Top 250 and set Max subjects per chart to 40.
  3. Untick Include short comments. Leave long reviews off.
  4. Click Start. My run finished in about two and a half minutes.
  5. Open the Overview tab, then export as CSV, Excel or JSON.

In Excel, the list fields (genres, countries) come out as joined text. That is fine for filtering. For anything heavier, use Python.

Option 2: Python with apify-client and pandas

Install the two libraries:

pip install apify-client pandas
Enter fullscreen mode Exit fullscreen mode

Then run the actor and load the results:

from apify_client import ApifyClient
import pandas as pd

client = ApifyClient("<YOUR_APIFY_TOKEN>")

run_input = {
    "charts": ["movie_top250"],
    "maxChartItems": 40,
    "includeComments": False,
    "includeReviews": False,
}

run = client.actor("liveclaude/douban-scraper").call(run_input=run_input)
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())

df = pd.DataFrame([i for i in items if i["recordType"] == "subject"])
df["name"] = df["originalTitle"].fillna(df["title"])
df["five_star_pct"] = df["ratingDistributionPercent"].apply(lambda d: d.get("5"))
df["wish_ratio"] = (df["wishCount"] / df["doneCount"]).round(3)

print(df["rating"].describe())
print(df[["chartRank", "name", "rating", "five_star_pct"]]
      .sort_values("five_star_pct", ascending=False)
      .head(5)
      .to_string(index=False))
Enter fullscreen mode Exit fullscreen mode

On my data the 40 ratings sat between 9.0 and 9.7, with a mean of 9.31 and a median of 9.3. The score alone barely separates them. The star distribution does a better job. The Shawshank Redemption had 85.4% five-star votes, Farewell My Concubine (霸王别姬) 82.3%, Witness for the Prosecution 81.9%.

The wish_ratio column is the one I find more interesting for release planning. It divides "want to watch" by "watched", which is a rough measure of untapped interest:

print(df[["chartRank", "name", "year", "wish_ratio"]]
      .sort_values("wish_ratio", ascending=False)
      .head(5)
      .to_string(index=False))
Enter fullscreen mode Exit fullscreen mode

The top of that list was mostly older films. Witness for the Prosecution (1957) had 0.544, so roughly one person wants to see it for every two who have. 12 Angry Men (1957) had 0.492 and Gone with the Wind (1939) 0.387. Compare that with The Shawshank Redemption at about 0.09. For a distributor or a streaming catalogue team, a high ratio on an old title is a hint that a rerelease or a licence might find an audience.

A quick look at where the films come from:

print(df.explode("countries")["countries"].value_counts().head(5))
Enter fullscreen mode Exit fullscreen mode

In the first 40 titles, 美国 (USA) appeared 22 times, mainland China 6, the UK 6 and Hong Kong 5. Co-productions count once per country, so the numbers add up to more than 40.

Scheduling and integrations

Charts like movie_showing and movie_real_time_hotest change daily, so they work well on a schedule. Create a saved task with your input, add a daily schedule in Apify, and each run lands in a new dataset you can compare with the day before. A shift in rating or wishCount for a film in cinemas shows up quickly.

The actor works with the Apify API, webhooks and the usual integrations (Google Sheets, n8n, Make, Zapier). You can also call it from an AI agent through the Apify MCP server. If you only need a few titles, subjectUrls with a short list is the cheapest way to track them.

Pricing per 1,000 results

The actor uses pay per result pricing. You pay for records saved to the dataset:

Record Price per 1,000
Subject (title with ratings and metadata) $3.00
Short comment $2.00
Long review, full text included $10.00

My run of 40 subjects with no comments cost about 12 cents. If you add 20 comments per title for the same 40 films, that is 800 comments, roughly another $1.60. Long reviews are the expensive part, so keep maxReviewsPerSubject low unless you need the text. You can set a maximum cost per run in the run options.

Limits to know

Without a Douban account the site shows about 150 short comments and about 50 long reviews per title, sorted by helpfulness. Newest-first order needs a login, and the actor does not log in. A few titles are hidden from logged-out visitors. Those end up in the ERRORS record in the run's key-value store instead of the dataset. If Douban blocks the requests and nothing comes back, the run fails on purpose so you are not charged for an empty dataset. The README suggests trying again later or switching the proxy to residential.

Responsible use

The actor reads only what a logged-out visitor can see, and it leaves out personal data of commenters by design. Comment and review text is still user-written content. If you publish quotes, keep them short and do not try to trace them back to people. Check Douban's terms and the rules that apply to you (GDPR in the EU, PIPL for data about people in China) before storing or sharing the data, and keep request volumes reasonable.

This tutorial was written with AI assistance and checked by the author. All numbers come from a real run of the scraper.

Top comments (0)