Create CSV File with ScreenScraping Results

Hi,

How do I build a CSV with my “fulltext element selectors” from my screen scraping results which individually have been assigned variables, into column and rows appropriately in a CSV file?

@Bradley_Mckinnon, one possible solution (I use this).

  1. Get the values into variables, which you have probably already done.

  2. Use a “Generate Data Table” activity.

  3. Choose a column separator if you don’t want the default (here I use “|” because it doesn’t usually appear in text, unlike the comma, semicolon and single or double quote), and a Newline separator if needed.

  4. Build a string for the Input property. Here’s an example:

    " " + employeeName + “|” + " " + company + “|” + " " + address + “|” + " " + workPhone + “|” + " " + workFax + “|” + email + “|” + " " + website + “|” + " " + focusArea + “|” + " " + country + “|” + " " + codeLanguages + “|” + " " + otherSkills

  5. For the output, create a datatable variable (say, ‘tempDT’)

  6. Open an “Excel application scope” activity.

  7. Append range (“sheet1” for example, “tempDT”)

  8. Clear datatable (that’ll be ‘tempDT’ in my example).

In your case, you might try a “Write CSV” activity, but note if you do this you might need to use a colon or semicolon as a separator instead of a pipe. Andrzej pointed this out here.. I haven’t tested that hypothesis yet, though - maybe it’ll work with the pipe. I’ll edit this if it does.

Hope that helps.
Regards,
burque505

1 Like

Hi,

Thanks! I shall give this a try!

Please do let me know if it doesn’t work for you.
Regards,
burque505

Hi,
So I have managed to assign columns etc but now it seems my variables are not actually presenting data in the csv as shown below;

uipath sheet

Here’s the project i’m working on: Main.xaml (24.5 KB)

@Bradley_Mckinnon, I can’t step through the workflow because it faults at the 'Attach Browser ‘Your Order Page’ activity. From looking through the workflow, though, I think @palindrome’s post regarding adding data rows and ArrayRow properties will get you there. Look at your last ‘Add Data Row’ activity: your problem is almost certainly there. Look at this screenshot:

add_data_row

You can’t see it in the screenshot (I can’t capture it), but the tooltip when you hover over the red squiggle under the ‘d’ in “bnetOrderTable” says " ‘}’ expected." (It seems to me it should throw a validation error, but it doesn’t.) What apparently is getting passed into your .csv in Row 2 is the names of the tables, as strings. I think you’re almost there - once you get the actual values and not the strings with the name of the tables in there, you should have it.

Would you mind posting your workflow once again when you get it running correctly? I’m sure you’re very close indeed.

Regards,
burque505

@burque505, here is my current workflow: Main.xaml (24.3 KB)

Only difference is the quotations have been removed from the “ArrayRow” input box, therefore leaving me with blank rows.

UPDATE: With the above changes I made and useing “{bnetOrder,bnetTimeStamp,bnetProductTitle,bnetGameKey}” in the ArrayRow input box, I now have the results shown in the spreadsheet.

However the “Game Key” results is showing an erroneous result (1.85438496070455E+24) instead of the key which should of been “1854384960704555165624690”

As shown below:

ui3

UPDATE:2: It seems only my excel app is throwing that false result. However on Google Sheets, it shows the results perfectly. Could that be Excel not parsing the CSV properly?

1 Like

@Bradley_Mckinnon,
EDIT: Glad you got it working! I’m editing my post to make it clear that what I wrote (in quotes) is not the best way to approach this. :slight_smile: There’s a more direct route. I’ve posted a little example workflow in the post under @andrzej.kniola’s post.

I don’t have any clue what the data is, but please try the attached workflow, modifying it as you need to. I’m shooting in the dark because I don’t know what’s in each row of the table I reference. (If the data doesn’t get passed in correctly, please try removing my assigns for “order”, “timestamp”, “product”, and “gamekey”, to see if the defaults get passed in.)

All this relies on changing the ArrayRow property and not the DataRow property.

You may very well have to change the values I have like “bnetGameKeyTable.Rows(1).Item(1).ToString” to different row and item numbers (I don’t know what’s in there).

If this approach doesn’t work, try something from what’s below, for DataRow instead of ArrayRow:

EDIT: What I described earlier below is too murky. See @aksh1yadav’s post here for a much, much clearer explanation of how to use the DataRow property.

As @palindrome suggested in the post above:

Use assign to add value to specific cell. example: dt.Row(6).Item(6)=value To add blank row in datatable use {} in array row and Datatable as tablename.

So, perhaps the solution is something like this (remember I don’t have access to your data and can’t step through the workflow):

  1. In your last ‘Add data row’, create a blank row first by adding ‘{}’ in the ArrayRow property. That gets you a blank row you can fill in.
  2. Fill the values in for the DataRow object. See @palindromes post, and:
    DataRowCollection.Add Method (System.Data) | Microsoft Learn.

Regards,
burque505

McKinnon2_burque505.xaml (26.6 KB)

1 Like

You’re correct, its only Excel display issue. It auto-formats long numbers to scientific notation. Since this is a csv file, I’d recommend a text editor like notepad++ instead, as it doesnt mess with formatting to “help”.

2 Likes

@Bradley_Mckinnon, well done! I see you updated your post after my last reply above.

For anyone else that might be having problems with this issue, by all means see @aksh1yadav’s post here.

Also, the docs at Insert DT How-To are really helpful.

I’ve added another little workflow that shows how to use both ArrayRow and DataRow properties in the ‘Add Data Row’ activity, and re-upped @aksh1yadav’s workflow here for convenience.

Regards,
burque505

Abs@sample.xaml (8.3 KB)
Data_Row_examples.xaml (15.4 KB)

1 Like