Fly to the sky & Return

website Crawling code for naver.com by c# 본문

프로그래밍/c# & VB 등

website Crawling code for naver.com by c#

낼은어떻게 2023. 2. 16. 13:42
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
 
class Program {
    static void Main(string[] args) {
        string url = "https://www.naver.com";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader stream = new StreamReader(response.GetResponseStream());
        string html = stream.ReadToEnd();
        stream.Close();
        response.Close();
 
        Regex regex = new Regex(@"(?<=<a href="")[^""]+(?="")");
        MatchCollection matches = regex.Matches(html);
        foreach (Match match in matches) {
            Console.WriteLine(match.Value);
        }
    }
}
cs