Sort a Data Scraped Result According to a condition

Hi Guys,
I am having a doubt regarding data scraping. I data scraped a content in a website and I am having the results in a variable. I wrote it to a csv to check it. The extracted datatable contains a list of items.

Now what I am looking forward is to do some kind of sort from the Extracted datatable using Uipath Activities.

I need to get only the fares of all hotels with name “A”. I need the output ‘fare’ to be stored in a variable so that I can use it further.I am attaching a screenshot along with this.

I used Assign activity to .SELECT(“hotel name=‘A’”).let this be stored in variable 1 I need to extract the corresponding fares of Hotel ‘A’ and store it in another variable.Let it be variable2

Thanks in Advance

You have already provided the solution.

  1. Create a variable of type DataRow - say var is the variable name
  2. Assign ExtractDataTable.Select(“Hotel Name=‘A’”)
    Note : ExtractDataTable is the output datatable of the data scrapping activity

In the data row output you will have the fare and hotel name both.
It can be accessed using for each of item in var

item(0) gives first element and item(1) second element
item(Fare) and item(Hotel Name)

Thanx for quick response. i am having a variable with datatable containing fare and hotel name with A. I need to extract only the fare for A into a variable.With ur method it will iterate through the list right??

How to store only the corresponding fare of A

This will filter all and keep only “A” related data.

Plz correct me if Iam wrong…

For each item(0) ie:fare

Inside FOR we have to put an Assign and store the first column to a new variable right…??? This new variable will be having the fares for A??

Yes Right,

var1 = item(Fare)

Keep in mind if you want to store all the Fare then create a list data type variable for var1.
Otherwise data will be overwriten when for each will run and finally only the last value u can get.

I want all the data…So I will go with the list datatype.Anyway tanx a lot.will check and give u an update soon

If you are new I will suggest just add a message box and print

you will get the feel of its working.
Then go for next step.

1 Like

One more thing. Lets say I am having the list of fares for A.

How to take the first value when workflow is executed first
Amd then the 2nd value for 2nd run
3rd value for 3rd run etc.

Its like i need to take the fare 1 and do a job and after that the same job with fare 2 etc…


Tried doing so, I sorted the list containing A to a variable lets say ‘var’. Then I tried by putting FOR EACH ITEM activity in var, inside for GET ROW ITEM with column name or index right?

As EXTRACTED DATATBLE variable type is datatable and variable type of var is datarow array(tried with generic and datatable variable type for var, only array datarow ends with no error).

  1. Can you tell me the datatype of item
  2. have u tried just putting message box.
  3. The extracted data table is having headers or not to check this just try to write the datatable in excel sheet.
    use excel scope and then write range specify datatable name.
  1. datatype of item given was generic which resulted in error, but gave string datatype which ended up with no error.

2 Yes, but got some error like below:

Option strict on disallows implicit conversions from string to integer

  1. we are getting the scrapped data with header in excel


if array of strings is arr = {“a”,“b”,“c”}
if you want to iterate this list then you will use item datatype as string

As you are iterating through an array of type DataRow so item should be of datatype Datarow.

We tried item with datarow but got some errors.

Mention Item(0).ToString and keep the variable vb2 as String.

tried that too. but no errors. but no message box popping up not even getting printed in write line

Please send the workflow.Its strange. (14.1 KB)

Refer this

You might have uploaded the incorrect workflow. I cannot see the code which you have attached which was not working.
Please attach the workflow in which for each was not working as desired