Skip to content

RPA for Python RPA Scripts

How to run these scripts

Assuming you have Python & RPA for Python installed you can execute the scripts by pasting the code into a .py file and running it from a terminal with the command:

Sample RPA Test Page

The web scripts reference a custom RPA Test Page

This script runs in headless mode (no browser is launched or harmed during the execution of this script).

The script workflow runs as follows:

  1. A web page is accessed

  2. A table on the page is extracted to CSV

  3. The CSV is converted to HTML

  4. The HTML Table is written to an HTML template

  5. The template is converted into a PDF with Puppeteer

Script 1: Convert Web Page CSV Data to HTML & then PDF

Script 1
import rpa as r

# Pandas is a Python library 
# that can carry out various file conversion/data analysis functions
import pandas

# use init() to start TagUI, it auto downloads TagUI on first run
r.init(headless_mode = True)
# r.init((headless_mode = True)(Turbo_mode = True))

# go to url

# get web page table data as csv - always useful
r.table(1, 'python_table.csv')

# launches Excel as the default csv editor

# convert csv to html with pandas

# ensure you have pip install pandas

r.wait (2)

file = pandas.read_csv("python_table.csv")


# load template code into index.html
r.write(r.load('template.html'), 'index.html')

# load table into index.html
r.write(r.load('python_table.html'), 'index.html')

r.write('<hr />' ,  'index.html')

# close html tags and write page
r.write('</body></html>', 'index.html')

# convert index.html to pdf with Puppeteer
# run node js file from python"py")

# close all 


The other 2 scripts on this page are called from

Script 2: Run Node js from RPA from Python

Script 2 -
from subprocess import check_output
p = check_output(['node', './pdfpage.js'])
print (p)

Script 3: Puppeteer File to PDF

Script 3 - pdfpage.js
// Use the File system & convert file to PDF

const puppeteer = require('puppeteer');
// Node.js file system module fs
// fs allows you to work with the file system on your computer.
// To include the File System module, use the require() method:
const fs = require('fs');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
   // set your html as the pages content from file system
  const html = fs.readFileSync(`${__dirname}/index.html`, 'utf8')
  await page.setContent(html, {
    waitUntil: 'domcontentloaded'
  await page.pdf({ path: 'vpFSTable.pdf', format: 'a4', landscape: true, });

  await browser.close();

Video: Full Script


Download project scripts

RPA for Python Reference

RPA for Python Documentation

If you require support or help check out our services page.