Content Transformation Scripts
A Content Transformation script can be used to change Content properties at runtime. It's only safe to modify agent Contents in Content Transformation scripts. It's not safe to modify sub-Contents in a Content Transformation script. You should only modify the current Content.
Content Transformation is available on the Extracted Content Tab.
Content Transformation Provide Various Languages for Transformation.
Content Transformation also provides the option to open a Full-Size Editor Window for easy scripting.
Once you click on the Button “Open Full Sized Editor” it will open the Editor in the Full Sized window.
The following are examples for Transforming the content using different scripting languages in the Transformation window.
Regex
Here’s an example script that extracts the first word of a content using a regular expression (Regex):
Interestingly the Sequentum Cloud Provides the feature to Auto Generate Regex for you. Follow the below steps to generate the Regex from the Extracted content.
Select the content you want from the extracted content.
Once the required content is selected the “Transform” button will change to “Extract Selected”.
Click on the “Extract Selected” button and it will generate the Regex for you and will show the result on the right side.
Click on the “Transformation” button and it will open the Transformation scripting window where you can see the “Auto Generated” Regex.
C#
The following example extracts the first word of the extracted content.
public string TransformContent(string content, RunContext context)
{
// Extract the first word from the extracted content.
return content.Split(" ")[0];
}
The script above uses the “content” Content which is of “string” type and returns the extracted content only. Most importantly it can’t be updated by scripting. However, the “content” Content has some string methods that can be used on the extracted content for modifying the content as per the need. The above script uses the “Split” method to split the content with “ ” as a separator and then uses index “0” to get the first word.
The below code shows the example of getting the Cookies or Proxy, etc.
public string GetData(RunContext context)
{
return context.ActionResult.GetReturnValue("cookie");
}
Note: Please enable the option “Capture response headers and cookie” from the “Browser” property of “URL & link” Contents. To get the value of the cookie.
The above code used the “context” Content to use the methods to get the “Cookies”.
Python:
The following example extracts the first word of the extracted content.
CODEfrom se_scripting_utils import * def transform_content(content: str, context: RunContext): return content.split(" ")[0]
The script above uses the “content” Content which is of “string” type and returns the extracted content only. Most importantly it can’t be updated by scripting. However, the “content” Content has some string methods that can be used on the extracted content for modifying the content as per the need. The above script uses the “Split” method to split the content with “ ” as a separator and then uses index “0” to get the first word.
The below code shows the example of getting the Cookies or Proxy, etc.
Note: Please enable the option “Capture response headers and cookie” from the “Browser” property of “URL & link” Contents. To get the value of the cookie.
from se_scripting_utils import *
def get_data(context: RunContext):
return context.action_result.get_return_value("cookie")