The source here https://yadi.sk/d/0If7C5jZ3CEhmf
Made on the basis of SefSimple.
Please take a look. I'm new and I look forward to any recommendations.
How use
- Code: Select all
Code in C#
// Extension Method
//IConfiguration WithDefaultLoader(this IConfiguration configuration, Action<LoaderSetup> setup = null, IEnumerable<IRequester> requesters = null);
var config = Configuration.Default.WithDefaultLoader();
// Set address site
var address = "https://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes";
// load and parse
//Extension Method
//Task<IDocument> OpenAsync(this IBrowsingContext context, string address);
var document = BrowsingContext.New(config).OpenAsync(address).Result;
// Use CSS selector
var rowSelector = "tr.vevent";
var rows= document.QuerySelectorAll<IHtmlTableRowElement>(rowSelector);
foreach (var str in rows)
This code in TypeScript
- Code: Select all
let Net = NetObject.NetWrapper;
let $$ = NetObject.FlagDeleteObject; // The symbol for the sign removal at the call of the object as a method
// Load Assembly AngleSharp
let AssemblyAngleSharp = Net.Assembly("AngleSharp");
// Get using types
let Configuration = AssemblyAngleSharp .GetType("AngleSharp.Configuration");
let BrowsingContext = AssemblyAngleSharp .GetType("AngleSharp.BrowsingContext");
let HtmlParser = AssemblyAngleSharp .GetType("AngleSharp.Parser.Html.HtmlParser");
let IHtmlTableRowElement = AssemblyAngleSharp .GetType("AngleSharp.Dom.Html.IHtmlTableRowElement");
let ApiExtensions = AssemblyAngleSharp .GetType("AngleSharp.Extensions.ApiExtensions");
let Default = Configuration._Default;
var config = Default.WithDefaultLoader();
var address = "https://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes";
let Context = BrowsingContext.New(config);
//Method Extencion
//Task<IDocument> OpenAsync(this IBrowsingContext context, string address);
let document = await Context.async.OpenAsync(address);
// I can not install the result of an asynchronous function class Proxy with Target fuction
// Therefore, the objects need to manually wrap
document = NetObject.WrapResult(document, true);
let rowSelector = "tr.vevent";
// For generics not finde in Extension
//let rows = document.QuerySelectorAll([IHtmlTableRowElement], rowSelector);
// Use Method Extencion
//IEnumerable < TElement > QuerySelectorAll<TElement>(this IParentNode parent, string selectors) where TElement : IElement;
let rows = ApiExtensions.QuerySelectorAll([IHtmlTableRowElement], document, rowSelector);
// and so you can call, but you need to beat all the options
//let rows = document.QuerySelectorAll(rowSelector);
// Select Rows
for (let row of rows) {
let Cells = row._Cells;
let i = 0;
let dataSite= new DataSite();
this.ResultParse.push(dataSite);
// Load value cels in dataSite
for (let Cell of Cells) {
// It is necessary to wait for the iterator that would release the reference to the iterator
if (i < 8) {
dataSite[this.Colums[i]] = Cell._TextContent;
Cell($$); // Remove the link from the repository objects
i++;
}
}
Cells($$);
row($$);
}
rows($$);
// Remove all links from the repository objects
NetObject.DeleteNetObjets(СборкаAngleSharp, Configuration, BrowsingContext, HtmlParser, IHtmlTableRowElement, ApiExtensions, Default, config, Context, document);
alert("The number of items in the store"+Net.CountItemsInStore());
First of all, we see the main differences between C #. To obtain the properties you want to add "_"
- Code: Select all
let Default = Configuration._Default;
To invoke an asynchronous method need to add a keyword async:
- Code: Select all
let document = await Context.async.OpenAsync(address);
To call a generic method, if it is impossible to deduce the types of the parameters that specify the arguments in the array:
- Code: Select all
let rows = ApiExtensions.QuerySelectorAll([IHtmlTableRowElement], document, rowSelector);
And most importantly, you need to manually delete the reference to the object from .Net
- Code: Select all
Cells(NetObject.FlagDeleteObject);
Small
- Code: Select all
Cells($$);