Introduction
In my previous article, we learned about Robotic Process Automation (RPA). We also saw the installation of popular RPA tool UiPath (free community edition on Windows machine) and we created a sample project in UiPath. If you are new to RPA or UiPath, please refer to this article to get the basic idea about UiPath and its working principles.
This article is in continuation of the previous article and we will learn about data scraping from a website and saving data to the SQL Server. I will fetch some user data from the C# Corner site and save it to different variables. Later, I will save these variables to the SQL Server database.
Data scraping or web scraping is the process of importing data from a website and saving it to your local system or any other device. It’s one of the most efficient ways to get data from the web, and in some cases to channel that data to another website.
Create UiPath Project in UiPath Studio

We can add “Input Dialog” activity to sequence. Please search for “Input Dialog” and drag to the sequence.
I have created the variable with “String” variable type and scope as “Sequence”. Please note I have given my C# corner user id as the default value. The default is not mandatory.

You can drag this activity next to “Input Dialog” activity. Give the C# corner URL to this activity. Please note I have concatenated the URL value with User Id variable so that “Open Browser” activity will open the web page of the C# Corner user which we will capture from the Input Dialog box.
We can define the browser type property. We can add one more variable to define the Browser. This new variable will be used to close the browser tab after we fetch the data from the website. The type of this variable must be “UiPath.Core.Browser”.
Choose the custom data type from drop down.




When our process starts, the browser will open in Google Chrome with the variable. Later, we will use this browser variable to close the Browser tab.

You can click the “Indicate element inside browser” link button to mark the position of data which we want to fetch from the website. Here I am going to fetch “User Name” from the C# Corner website.

- CREATE TABLE [dbo].[CsharpCorner](
- [Id] [bigint] IDENTITY(1,1) NOT NULL,
- [UserId] [varchar](25) NULL,
- [UserName] [varchar](50) NULL,
- [UserRank] [varchar](25) NULL,
- [UserRead] [varchar](25) NULL,
- [UserReputation] [varchar](25) NULL,
- [MemberType] [varchar](25) NULL,
- [RecordCreatedOn] [datetime] NULL,
- CONSTRAINT [PK_CsharpCorner] PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- ))
- GO
- ALTER TABLE [dbo].[CsharpCorner] ADD
- CONSTRAINT [DF_CsharpCorner_CreatedOn]
- DEFAULT (getdate()) FOR [RecordCreatedOn]

Please note this activity will not find the default activity library. We can search for additional packages. Please click “Search in available packages” link

After installation is complete, you can click the “Save” button. This will download the dependencies to our current project.

You can choose the connection properties like Server name and authentication type.

- "insert into csharpcorner (UserId,UserName,UserRank,UserRead,UserReputation,MemberType) values ('" +
- varUserId +"','"+ varUserName +"','"+ varUserRank + "','"+ varUserRead + "','"+ varUserReputation + "','"+ varMemberType + "')"
The above activity will insert a new record to SQL Server table with fetched data.
You can drag this activity next to "Execute Non-Query” activity.
You can map the previously created Browser variable with this activity so that it will close the browser tab after fetching and inserting the data to SQL Server.





Summary
In this article, we have seen how to fetch data from a website and save to the SQL Server database. For that, we have used many activities like “Input Dialog”, “Open Browser”, “Get Text”, “Execute Non Query”, “Close Tab” and “Message Box”. We have also seen how to install an external library and dependencies to the current project.
We will see more exciting features of UiPath in upcoming articles.

Deepti ChaudhariPosted Sep 16, 2019, 12:33 AM
Where do i will get my userid?