Created
March 24, 2016 17:55
-
-
Save jayu108/14c331178ef1585e157b to your computer and use it in GitHub Desktop.
C# , HTML Agility Pack 사용한 html 파싱
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using HtmlAgilityPack; | |
namespace HtmlParsing | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
String myHtml = @"<body> | |
<p>It is better to use the style attribute (instead of the width and height attributes), because it prevents | |
internal or external styles sheets to change the original size of an image:</p> | |
<img src=""html51.gif"" alt=""HTML5 Icon"" style=""width:128px;height:128px;""> | |
<img src=""html52.gif"" alt=""HTML5 Icon"" width=""128"" height=""128""> | |
</body>"; | |
// Console.WriteLine(myHtml); | |
HtmlAgilityPack.HtmlDocument mydoc = new HtmlAgilityPack.HtmlDocument(); | |
mydoc.LoadHtml(myHtml); | |
HtmlAgilityPack.HtmlNodeCollection nodeCol = mydoc.DocumentNode.SelectNodes("//img"); | |
foreach (HtmlAgilityPack.HtmlNode node in nodeCol) | |
{ | |
Console.WriteLine(node.OuterHtml); | |
Console.WriteLine(node.Attributes["src"].Value); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment