I’m having a problem with Automation Studio in Parsing data from a multi-line text field. I want each line in a separate variable and I’ve tried Python and Ruby to do this but the examples and sample codes just don’t seem to be complete enough. I’m able to get the data into the code but unable to get it to export the code into the variables that I have setup:
def handle_starttag(self, tag, attrs):
for attr in attrs:
if attr[0] == 'class' and attr[1] == 'MsoNormal':
self.counter += 1
def handle_data(self, data):
if data.strip() and self.counter > 0:
self.current_data += data.strip()
self.variables[f'var_{self.counter}'] = self.current_data
def handle_endtag(self, tag):
if tag == 'div':
self.current_data = ""
def split_text_to_variables(multi_line_text):
lines = multi_line_text.split(‘\n’)
variables = {}
for i, line in enumerate(lines):
variable_name = f’var_{i+1}’
variables[variable_name] = line
return variables
def main(input):
# Access the values of the action’s Input fields
body = input[‘Body’]
# Split the text to variables
text_variables = split_text_to_variables(body)
# Create a parser instance
parser = MyHTMLParser()
# Feed the HTML content to the parser
parser.feed(body)
# Combine both sets of variables
combined_variables = {**text_variables, **parser.variables}
return combined_variables