Looks like the list also have the json inside the page: https://www.imdb.com/pt/chart/top/
This snippet return all top 250:
I build in this way to be easy to load and check in one step in python, this also allow get the movie details easily.
import requests, json, jmespath
from lxml import html
url = f"https://www.imdb.com/pt/chart/top/"
resp = requests.get(url, headers={"User-Agent": "Mozilla/5.0"})
if resp.status_code != 200:
logger.error("Error fetching %s: %s", url, resp.status_code)
raise Exception(f"Error fetching {url}")
tree = html.fromstring(resp.content)
script = tree.xpath('//script[@id="__NEXT_DATA__"]/text()')
if not script:
logger.error("No script found with id '__NEXT_DATA__'")
raise Exception("No script found with id '__NEXT_DATA__'")
raw_json = json.loads(script[0])
processed_json = jmespath.search("props.pageProps.pageData.chartTitles.edges", raw_json)
movies = {}
for item in processed_json:
movies.update({
item['node']['id']: {
'rank': item['currentRank'],
'title': item['node'].get('titleText', {}).get('text'),
'year': item['node'].get('releaseYear', {}).get('year'),
'rating': item['node'].get('ratingsSummary', {}).get('aggregateRating'),
'ratingCount': item['node'].get('ratingsSummary', {}).get('voteCount')
}
})
json_dumps = json.dumps(movies, indent=2, ensure_ascii=False)
print(json_dumps)
The data returned:
{
"tt0111161": {
"rank": 1,
"title": "Um Sonho de Liberdade",
"year": 1994,
"rating": 9.3,
"ratingCount": 3088087
},
"tt0068646": {
"rank": 2,
"title": "O Poderoso Chefão",
"year": 1972,
"rating": 9.2,
"ratingCount": 2153202
}
...
}
Looks like the list also have the json inside the page: https://www.imdb.com/pt/chart/top/
This snippet return all top 250:
I build in this way to be easy to load and check in one step in python, this also allow get the movie details easily.
The data returned:
{ "tt0111161": { "rank": 1, "title": "Um Sonho de Liberdade", "year": 1994, "rating": 9.3, "ratingCount": 3088087 }, "tt0068646": { "rank": 2, "title": "O Poderoso Chefão", "year": 1972, "rating": 9.2, "ratingCount": 2153202 } ... }