private void WriteCSV(StreamWriter sw, ScrappingNode list, IHTMLElement item, int index, String parentkey = "") { String tagnameIndex = String.Format("{0}[{1}]", item.tagName, index); IHTMLDOMNode node = item as IHTMLDOMNode; if (!browser.DenyTag.Contains(item.tagName)) { if (node.firstChild == null || IsChildTextNode(node)) { StringBuilder sb = new StringBuilder(); if (parentkey != null && !String.Equals(String.Empty, parentkey)) { sb.Append(parentkey).Append("/"); } sb.Append(tagnameIndex).Append(","); sb.Append(item.tagName).Append(","); sb.Append(item.id).Append(","); sb.Append(item.className).Append(","); String buffer = item.outerHTML; if (buffer != null) { buffer = buffer.Replace("\r\n", "").Replace("\n", ""); } sb.Append(buffer); sw.WriteLine(sb.ToString()); } } int indexChild = 0; try { foreach (IHTMLElement subNode in item.children) { WriteCSV(sw, list, subNode, indexChild, parentkey != null && !String.Equals(String.Empty, parentkey) ? parentkey + "/" + tagnameIndex : tagnameIndex); indexChild++; } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void finalize(WebBrowser obj) { node = new ScrappingNode(this, obj.Document); Complate = true; Scrapped(); }