Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- var config = new Configuration().WithDefaultLoader();
- var document = BrowsingContext.New(config).OpenAsync(Url.Create("http://www.w3.org/TR/css3-background/#ltboxgt")).Result;
- Dictionary<string, string> atribute = new Dictionary<string, string>()
- {
- {"Name","tr:nth-child(1) > td"},
- {"Value ","tr:nth-child(2) > td"}
- };
- WriteAtributeToFile(document, atribute, "table.propdef tbody", @"D:\myOutput.csv");
- }
- private static void WriteAtributeToFile(IDocument document, Dictionary<string, string> atribute, string selector, string file)
- {
- using (var stream = new StreamWriter(file))
- {
- stream.WriteLine(string.Join(",", atribute.Select(a => a.Key)));
- foreach (var item in document.QuerySelectorAll(selector))
- {
- foreach (var i in atribute.Select(a => a.Value))
- {
- stream.Write(item.QuerySelector(i).TextContent.Replace("\n", "").Replace(",", ""));
- stream.Write(",");
- }
- stream.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement