0

I have a source html page and I want to do the following:

  1. extracting a specific string from the whole html page and save the new choosing string in a new html page.
  2. creating a database on MySQL with 4 columns.
  3. importing the data from the html page to the table on MySql.

I would be pretty thankful and grateful if someone could help me in that cause I have no that perfect knowledge of using C#.

ganchito55
  • 3,559
  • 4
  • 25
  • 46
  • 2
    For the HTML part, what you're looking for is called a "DOM parser". As an example, take a look at a library called the HTML Agility Pack in .NET. It can parse an HTML document and allow you to easily extract parts of that document. For the database part, look for some tutorials and examples on using MySQL in .NET. There are many available. – David Mar 19 '17 at 11:22
  • First of all, you are asking as for more than one questions. You should open a stackoverflow question for each problem. Then as @David has said, you can use HTML Agility Pack to manage the HTML, [here](http://stackoverflow.com/questions/846994/how-to-use-html-agility-pack) you have an example. – ganchito55 Mar 19 '17 at 11:35
  • All of us do not know all the stuff. So, if you ask one by one, the one who knows it would help you! – Prashanth Benny Mar 19 '17 at 11:56

1 Answers1

1

You could use this code :

HttpClient http = new HttpClient();

//I have put Ebay.com. you could use any.
var response = await http.GetByteArrayAsync("ebay.com"); 
String source = Encoding.GetEncoding("utf-8").GetString(response, 0, response.Length - 1);
source = WebUtility.HtmlDecode(source);
HtmlDocument Nodes = new HtmlDocument();
Nodes.LoadHtml(source);

In the Nodes object, you will have all the DOM elements in the HTML page.

You could use linq to filter out whatever you need.

Example :

List<HtmlNode> RequiredNodes = Nodes.DocumentNode.Descendants()
                                    .Where(x => x.Attributes["Class"].Contains("List-Item")).ToList();

You will probably need to install Html Agility Pack NuGet or download it from the link.

hope this helps.

Prashanth Benny
  • 1,523
  • 21
  • 33