Simple robot

This robot is included in our downloadable example robots. You can also find the code at the example robots repository.

This simple Robot Framework robot opens a web page, stores some text content, and takes a screenshot of an image element on the web page.

Run this robot locally in Robocorp Lab

You can run this robot on your local machine using Robocorp Lab:

  1. Set up your development environment.
  2. Download the example robots.
  3. Open the simple-web-scraper example.
  4. Open the tasks.robot file and run it.
  5. Try the Python version of the same robot! Open the tasks.py file and run it.

The robot written in Robot Framework

This version of the robot (tasks.robot) uses Robot Framework syntax:

# ## Simple web scraper robot
# Opens a web page and stores some content.

*** Settings ***
Documentation     A simple web scraper robot.
...               Opens a website.
...               Stores the web page text in a file in the output directory.
...               Saves a screenshot of an element in the output directory.
Library           RPA.Browser
Library           RPA.FileSystem

*** Variables ***
${URL}=           https://robotframework.org/

*** Tasks ***
Store Web Page Content
    Open Available Browser    ${URL}
    ${text}=    Get Text    scroller
    Create File
    ...    ${CURDIR}${/}output${/}text.txt
    ...    ${text}
    ...    overwrite=True
    Screenshot
    ...    css:.img-fluid
    ...    ${CURDIR}${/}output${/}screenshot.png
    [Teardown]    Close Browser

The robot written in Python

For comparison, this is the same robot written in Python (tasks.py):

from RPA.Browser import Browser
from RPA.FileSystem import FileSystem

browser = Browser()
file_system = FileSystem()
url = "https://robotframework.org/"


def store_web_page_content():
    browser.open_available_browser(url)
    text = browser.get_text("scroller")
    file_system.create_file("output/text.txt", text, overwrite=True)
    browser.screenshot("css:.img-fluid", "output/screenshot.png")


def main():
    try:
        store_web_page_content()
    finally:
        browser.close_all_browsers()


if __name__ == "__main__":
    main()