updated demos
This commit is contained in:
parent
b3958469b5
commit
de9f5f8f19
|
@ -1,35 +1,29 @@
|
|||
using ProSol.Html;
|
||||
using ProSol.Html.Contracts.Data;
|
||||
using ProSol.Html.Messaging;
|
||||
using ProSol.Messaging;
|
||||
using ProSol.Messaging.Filtering;
|
||||
using ProSol.Messaging.Translating;
|
||||
|
||||
// Get all links from the page:
|
||||
var url = "https://en.wikipedia.org/wiki/Food_energy";
|
||||
var html = HtmlSource.GetHtmlAsync(url).Result;
|
||||
|
||||
var provider = new TagsProvider();
|
||||
provider.Subscribe(new ConsoleLogObserver(html), "a");
|
||||
var data = new DataSubscriber<string>();
|
||||
|
||||
provider
|
||||
.Endpoint(x => x.CurrentTag.TagInfo.Name == "a")
|
||||
.Translate(x => html[x.CurrentTag.InnerTextRange])
|
||||
.Subscribe(data);
|
||||
|
||||
provider.Process(html);
|
||||
|
||||
Console.ReadKey();
|
||||
|
||||
internal class ConsoleLogObserver : ISubscriber<TagsProviderMessage>
|
||||
foreach (var item in data.Messages)
|
||||
{
|
||||
private readonly string html;
|
||||
|
||||
public ConsoleLogObserver(string html)
|
||||
{
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
public void OnCompleted() { }
|
||||
|
||||
public void OnNext(TagsProviderMessage value)
|
||||
{
|
||||
var text = html[value.CurrentTag.InnerTextRange];
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
|
||||
Console.ReadKey();
|
||||
|
||||
internal static class HtmlSource
|
||||
{
|
||||
internal static async Task<string> GetHtmlAsync(string url)
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ProSol.Html.TagsProvider" Version="2.0.0-rc1.3" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ProSol.Html.TagsProvider" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
25
ProSol.TagsProvider/TagsProvider.sln
Normal file
25
ProSol.TagsProvider/TagsProvider.sln
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TagsProvider", "TagsProvider.csproj", "{9ABC0B1C-7A37-424B-814E-F7CF89578BA2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9ABC0B1C-7A37-424B-814E-F7CF89578BA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9ABC0B1C-7A37-424B-814E-F7CF89578BA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9ABC0B1C-7A37-424B-814E-F7CF89578BA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9ABC0B1C-7A37-424B-814E-F7CF89578BA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {18FC775A-99A4-4916-B0AD-36CD7ED1D84F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,4 +1,4 @@
|
|||
using DevOvercome.WebScrap;
|
||||
using ProSol.WebScrap;
|
||||
|
||||
var request = "https://en.wikipedia.org/wiki/Food_energy";
|
||||
|
||||
|
@ -9,9 +9,8 @@ var html = await response.Content.ReadAsStringAsync();
|
|||
|
||||
// Run the WebScrapper:
|
||||
var css = "#firstHeading";
|
||||
var result = new WebScrapper(html)
|
||||
.Run(css)
|
||||
.AsJson()
|
||||
var result = WebScrapper
|
||||
.Run(html, css)
|
||||
.ToJsonString();
|
||||
|
||||
// Get the results:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DevOvercome.WebScrap" Version="1.0.0-rc.5" />
|
||||
<PackageReference Include="ProSol.WebScrap" Version="2.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in a new issue