티스토리 뷰
ParseHTML이라는 외부 라이브러리로 HTML을 파싱해보자.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HTML;
using System.IO;
namespace ParseHTMLTester
{
class Program
{
static void Main(string[] args)
{
StreamReader reader = new StreamReader("1.txt");// html을 1.txt로 저장해 놓음
HTML.ParseHTML parse = new HTML.ParseHTML();
// 스트림 리터에서 파일 전체를 string으로 변경
string data = reader.ReadToEnd();
parse.Source = data;
while (!parse.Eof())
{
char ch = parse.Parse();
if (ch == 0)
{
AttributeList tag = parse.GetTag();
if (tag.Name == "th")
{
// th일 경우 class의 값을 프린트
if (tag["class"] != null)
{
Console.WriteLine("th class=" + tag["class"].Value);
}
}
else
{
// 일반 태그는 그냥 프린트
Console.WriteLine(tag.Name);
}
}
}
}
}
}
'프로그래밍' 카테고리의 다른 글
Node.js Ubuntu에 설치하기 (0) | 2016.04.06 |
---|---|
Visual C++ Win32 타이머 CreateTimerQueueTimer 예제 (0) | 2016.04.06 |
Visual Studio 2013에서 MFC가 컴파일되지 않을때 (0) | 2016.04.06 |
C# 서버개발 관련 마영전 정리 (0) | 2016.04.06 |
C# HTTP Post Request (0) | 2016.04.06 |
- Total
- Today
- Yesterday