public static IEnumerable <T> Links <T>(this ParsedHtml self, Func <string, HtmlObject, T> selector) { return (from a in self.QuerySelectorAll("a[href]") let href = a.GetAttributeValue("href") where !string.IsNullOrWhiteSpace(href) select selector(self.TryBaseHref(href), a)); }
public static IQuery <HtmlObject> Tables(ParsedHtml html) => html.Tables(null).ToQuery();
public static IQuery <T> Links <T>(ParsedHtml html, Func <string, string, T> selector) => html.Links((href, ho) => selector(href, ho.InnerHtml)) .Select(link => link) .ToQuery();
public static IQuery <string> Links(ParsedHtml html) => Links(html, (href, _) => href);
public static IQuery <HtmlForm> Forms(ParsedHtml html) => Query.Return(html.Forms);
public static IQuery <DataTable> FormsAsDataTable(ParsedHtml html) { var forms = from f in html.Forms select f.GetForm((fd, fs) => new { f.Name, Action = new Uri(html.TryBaseHref(f.Action), UriKind.Absolute), Method = f.Method.ToString().ToUpperInvariant(), f.EncType, Data = fd, Submittables = fs, }); var dt = new DataTable(); dt.Columns.AddRange(new [] { new DataColumn("#") { AllowDBNull = false }, new DataColumn("FormName") { AllowDBNull = true }, new DataColumn("FormAction") { AllowDBNull = false }, new DataColumn("FormMethod") { AllowDBNull = true }, new DataColumn("FormEncoding") { AllowDBNull = true }, new DataColumn("Name") { AllowDBNull = false }, new DataColumn("Value") { AllowDBNull = false }, new DataColumn("Submittable", typeof(bool)) { AllowDBNull = false }, }); foreach (var form in from fi in forms.Select((f, i) => (i + 1).AsKeyTo(f)) let form = fi.Value from controls in new[] { from e in form.Data.AsEnumerable() from v in e.Value select new { e.Key, Value = v, Submittable = false }, from e in form.Submittables.AsEnumerable() from v in e.Value select new { e.Key, Value = v, Submittable = true }, } from control in controls select new object[] { fi.Key, form.Name, form.Action.OriginalString, form.Method, form.EncType, control.Key, control.Value, control.Submittable, }) { dt.Rows.Add(form); } return(Query.Singleton(dt)); }
public static IEnumerable <HtmlObject> Tables(this ParsedHtml self, string selector) => from e in self.QuerySelectorAll(selector ?? "table") where "table".Equals(e.Name, StringComparison.OrdinalIgnoreCase) select e;
public static IEnumerable <HtmlObject> Tables(this ParsedHtml html) => html.Tables(null);
public static IEnumerable <string> Links(this ParsedHtml html) => html.Links((href, _) => href);