public static void Clear() { webLongLob.Refresh(); StringBuilder logbox2 = new StringBuilder(webLongLob.DocumentText); logbox2.AppendFormat(HtmlMainContent.ToString(), style.ToString(), javascript.ToString()); webLongLob.DocumentText = logbox2.ToString(); }
public void scrapData(string Url, int cantidad) { browser = new System.Windows.Forms.WebBrowser(); browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(DocumentCompleted); HtmlDocument document = null; int contador = 0; HtmlWeb web = new HtmlWeb(); while (contador <= cantidad) { browser.Navigate(Url); browser.Visible = true; browser.Refresh(); while (completed) { System.Windows.Forms.Application.DoEvents(); Thread.Sleep(100); botonClik = browser.Document.GetElementById("btnMoreResults"); botonClik.InvokeMember("click"); document = (HtmlDocument)browser.Document.DomDocument; HtmlNode[] nodes = document.DocumentNode.SelectNodes(".//a/@href").ToArray(); Console.Write("Buscando Recetas....."); using (var progress = new ProgressBar()) { foreach (HtmlNode enlace in nodes) { foreach (HtmlAttribute atributo in enlace.Attributes) { if (RegexTool.isUrl(atributo.Value)) { HtmlDocument recipe = web.Load(atributo.Value); if (hasRecipe(recipe)) { contador++; progress.Report((double)contador / cantidad); Thread.Sleep(20); getMicroData(recipe); } } } } } } } Console.WriteLine("Listo."); Console.ReadLine(); }
private static string CreateTestHtml(string html, Dictionary <string, string> dic) { try { System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser(); wb.Navigate("about:blank"); var doc = wb.Document; doc.OpenNew(false); doc.Write(html); wb.Refresh(); var div = doc.CreateElement("div"); wb.Document.Body.InsertAdjacentElement(System.Windows.Forms.HtmlElementInsertionOrientation.AfterBegin, div); var table = doc.CreateElement("table"); div.AppendChild(table); { var tbody = doc.CreateElement("tbody"); table.AppendChild(tbody); { foreach (var keyv in dic) { var tr = doc.CreateElement("tr"); tbody.AppendChild(tr); var td1 = doc.CreateElement("td"); td1.Style = "font-weight:bold"; td1.InnerText = keyv.Key; var td2 = doc.CreateElement("td"); td2.InnerText = keyv.Value; td2.Style = "color:red"; tr.AppendChild(td1); tr.AppendChild(td2); } } } div.InsertAdjacentElement(System.Windows.Forms.HtmlElementInsertionOrientation.BeforeEnd, doc.CreateElement("hr")); return(wb.Document.Body.OuterHtml); } catch (Exception ex) { return(html); } }