IMDB Movie Review Sentiment Analysis with Amazon Comprehend

A robot that uses Amazon Comprehend to analyze IMDB movie review sentiments

This robot demonstrates how to do text sentiment analysis with Amazon Comprehend and Robocorp.

The robot navigates to IMDB, finds the RoboCop movie, analyses the user reviews, and stores the reviews and the sentiment analysis result into a CSV file.

The robot

*** Settings ***
Documentation       IMDB review sentiment robot.

Library             Browser
...                 jsextension=${CURDIR}${/}keywords.js
...                 strict=False
Library             Collections
Library             RPA.Cloud.AWS    robocloud_vault_name=aws
Library             RPA.Tables

*** Variables ***
${AWS_REGION}=              us-east-2
${MOVIE}=                   RoboCop
${REVIEW_MAX_LENGTH}=       ${2000}
${SENTIMENTS_FILE_PATH}=    ${OUTPUT_DIR}${/}imdb-sentiments-${MOVIE}.csv

*** Tasks ***
Analyze IMDB movie review sentiments
    Open IMDB
    Search for movie    ${MOVIE}
    @{reviews}=    Get reviews
    @{sentiments}=    Analyze sentiments    ${reviews}
    ${table}=    Create Table    ${sentiments}
    Write Table To Csv    ${table}    ${SENTIMENTS_FILE_PATH}

*** Keywords ***
    New Page

Search for movie
    [Arguments]    ${movie}
    Type Text    css=#suggestion-search    ${movie}
    Click    css=.react-autosuggest__suggestion--first a

Scroll page
    FOR    ${i}    IN RANGE    5
        Scroll By    vertical=100%
        Sleep    100 ms

Get reviews
    Click    text=USER REVIEWS
    ${review_locator}=    Set Variable .text
    Wait For Elements State    ${review_locator}
    Scroll page
    @{reviews}=    getTexts    ${review_locator}
    RETURN    ${reviews}

Analyze sentiments
    [Arguments]    ${reviews}
    Init Comprehend Client    use_robocloud_vault=True    region=${AWS_REGION}
    @{sentiments}=    Create List
    FOR    ${review}    IN    @{reviews}
        ...    Comprehend sentiment
        ...    ${review}[:${REVIEW_MAX_LENGTH}]
        &{sentiment}=    Create Dictionary
        ...    review=${review}
        ...    sentiment=${sentiment_score}
        Append To List    ${sentiments}    ${sentiment}
    RETURN    ${sentiments}

Comprehend sentiment
    [Arguments]    ${text}
    ${sentiment}=    Detect Sentiment    ${text}
    ${sentiment_score}=    Set Variable If
    ...    "${sentiment["Sentiment"]}" == "NEGATIVE"
    ...    ${-1}
    ...    ${1}
    RETURN    ${sentiment_score}

The RPA.Cloud.AWS library handles the communications with Amazon Comprehend.

The Playwright-based Robot Framework Browser library manages the browser automation duties.

The RPA.Tables library takes care of saving the data into a CSV file.


You need to provide your Amazon Comprehend API credentials so that the robot can communicate with the sentiment analysis service.

Learn how to use the Robocorp vault to store secrets.

Create a vault.json file for the credentials

Create a new file: /Users/<username>/vault.json

  "aws": {

Point devdata/env.json to your vault.json file

  "RPA_SECRET_MANAGER": "RPA.Robocorp.Vault.FileSecrets",
  "RPA_SECRET_FILE": "/Users/<username>/vault.json"

Control Room vault

Create a new secret using aws as the name. Add the AWS_KEY_ID and AWS_KEY key-value pairs.

I want to learn more!

Visit Robocorp docs to learn more about developing robots to automate your processes!

Robocorp portal contains many example robots with all the source code included.

Follow the Robocorp YouTube channel for automation-related videos.

Visit the Software Robot Developer forum to discuss all-things automation. Ask questions, get answers, share your robots, help others!

Discover more robots