Skip to content

Parsers

You can use parser methods to extract and access data in a more simplified way.

Table to Dict/Map Array

With this method it is possible to easily extract the contents of a <table> from the page and access it as a list of dictionaries/maps.

from botcity.web.parsers import table_to_dict

# Opening the page containing the table.
bot.browse("https://www.w3schools.com/html/html_tables.asp")

# Getting the <table> element.
table_element = bot.find_element("customers", By.ID)

# Converting content to a list of dictionaries.
table_data = table_to_dict(table=table_element)

# Each table row will be a dictionary.
# You can access the values using the column name as key.
# The format is: row['column'].
for row in table_data:
    print(f'''
    *** Information ***
    Company: {row['company']}
    Contact: {row['contact']}
    Country: {row['country']}
    ''')
import dev.botcity.framework.web.parsers.TableParser;

// Opening the page containing the table.
browse("https://www.w3schools.com/html/html_tables.asp");

// Getting the <table> element.
WebElement tableElement = findElement(By.id("customers"));

// Converting content to a list of Maps.
List<Map<String, String>> tableData = TableParser.tableToMapArray(tableElement);

// Each table row will be a Map.
// You can access the values using the column name as key.
for(Map<String, String> row : tableData) {
    System.out.println(row);
}