Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize C # data Collection based on ASP.NET Web Page

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to achieve C# data collection based on ASP.NET web pages". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to achieve C# data collection based on ASP.NET web pages"!

C# data collection can be divided into two parts:

A song:

Because we want to collect the content on other people's web pages, we first need to get the html code on the web page, so it is relatively simple to get the html code. Use WebClient's DownloadData (url) to take the byte array, and then convert it to a string string.

The specific code is as follows:

/ get the source code of the web page / URL path / Encoding method publicstringGetHTML (stringurl,stringencoding) {WebClientweb=newWebClient (); byte [] buffer=web.DownloadData (url); returnEncoding.GetEncoding (encoding) .GetString (buffer);}

Two-part series:

Now that we have the html code of the target page, we have to withhold the data we want at the beginning. There is no doubt that powerful regular expressions are needed to withhold data. Using the matching of regular expressions to get what we want, here we can filter out the html code, and the rest is the content.

The specific code of C# data collection is as follows:

Htmlhtml=newHtml (); / / get the html code of the specified page, * the parameters are url (seemingly known), the second is the coding set stringhtmlCode=html.GetHTML of the target web page ("http://gvod.tom59.cn/List.asp?ClassId=3","gb2312"); / / regular expression Regexregexarticles=newRegex (" (?. +). * "); / / the content of all matching expressions MatchCollectionmarticles=regexarticles.Matches (htmlCode) / / traversing matching content foreach (Matchminmarticles) {Console.Write ("title:" + m.Groups ["title"] .value + "\ n"); Console.Write ("id:" + m.Groups ["id"] .Value + "\ n"); Console.Write ("\ n"); at this point, I believe you have a deeper understanding of "how to implement C# data collection based on ASP.NET web pages". You might as well do it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report