Hello!
I use DataTable and AngleSharp.
Shows error while adding data to DataTable (below). Although there is no such error when using the standard VS DataGridView.What could be the problem?
System.ArgumentOutOfRangeException: The specified argument is out of range.Parameter name: index at AngleSharp.Common.ObjectExtensions.GetItemByIndex [T] (IEnumerable`1 items, Int32 index) at AngleSharp.Dom.HtmlCollection`1.get_Item (Int32 index)
My code:
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("Ip", Type.GetType("System.String"));
dt.Columns.Add("Port", Type.GetType("System.String"));
dt.Columns.Add("Country", Type.GetType("System.String"));
dt.Columns.Add("Anonymity", Type.GetType("System.String"));
dt.Columns.Add("Google", Type.GetType("System.String"));
dt.Columns.Add("Https", Type.GetType("System.String"));
proxyGrid.ShowRowHeader = true;
proxyGrid.AllowFiltering = true;
proxyGrid.DataSource = dt;
}
async Task StartCrawl()
{
try
{
var config = Configuration.Default.WithDefaultLoader().WithCss().WithJs();
var address = "url";
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(address);
var trs = document.QuerySelectorAll(".table-responsive tbody tr");
foreach (var item in trs)
{
if (item != null)
{
var tds = item.QuerySelectorAll("td");
if (tds != null)
{
dt.Rows.Add(new object[]
{
tds[0].TextContent,
tds[1].TextContent,
tds[3].TextContent,
tds[4].TextContent,
tds[5].TextContent,
tds[6].TextContent,
});
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
MessageBox.Show("Collect");
}
}
The problem has been resolved. Edited QuerySelector. True, it remained unclear why this did not occur in the standard DataGridView
Thanks