-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Velka-DEV/dev
Added samples (and removed ghost sln Migale project)
- Loading branch information
Showing
5 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Migale.HttpClient\Migale.HttpClient.csproj" /> | ||
<ProjectReference Include="..\Migale.Playwright\Migale.Playwright.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using Migale.Samples.samples; | ||
|
||
await HttpClientSample.RunHttpClientMigaleAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Migale.Core; | ||
using Migale.HttpClient.Extensions; | ||
|
||
namespace Migale.Samples.samples; | ||
|
||
public class HttpClientSample | ||
{ | ||
public static async Task RunHttpClientMigaleAsync() | ||
{ | ||
var builder = new MigaleBuilder(); | ||
|
||
builder.WithHttpClientCrawler(); | ||
|
||
var spider = builder.Build(); | ||
|
||
spider.PageCrawlStarting += (sender, e) => | ||
{ | ||
Console.WriteLine($"Crawling {e.Target.Url}"); | ||
}; | ||
|
||
spider.PageCrawled += (sender, e) => | ||
{ | ||
Console.WriteLine($"Crawled {e.Target.Url}"); | ||
}; | ||
|
||
spider.PageCrawlFailed += (sender, e) => | ||
{ | ||
Console.WriteLine($"Failed to crawl {e.Target.Url}"); | ||
}; | ||
|
||
for(var i = 0; i < 10; i++) | ||
{ | ||
spider.AddTarget("http://example.com"); | ||
} | ||
|
||
await spider.StartAsync(); | ||
|
||
Console.WriteLine("Press any key to exit"); | ||
|
||
Console.ReadKey(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Migale.Core; | ||
using Migale.Core.Models; | ||
using Migale.Playwright.Extensions; | ||
using Migale.Playwright.Models; | ||
|
||
namespace Migale.Samples.samples; | ||
|
||
public class PlaywrightSample | ||
{ | ||
public static async Task RunPlaywrightMigaleAsync() | ||
{ | ||
var exitCode = Microsoft.Playwright.Program.Main(new[] {"install"}); | ||
if (exitCode != 0) | ||
{ | ||
throw new Exception($"Playwright exited with code {exitCode}"); | ||
} | ||
|
||
var builder = new MigaleBuilder(); | ||
|
||
builder.WithPlaywrightCrawler(new PlaywrightCrawlerOptions() | ||
{ | ||
Headless = false, | ||
BrowserInstances = 1 | ||
}); | ||
builder.WithOptions(new MigaleOptions() | ||
{ | ||
Threads = 1 | ||
}); | ||
|
||
var spider = builder.Build(); | ||
|
||
spider.PageCrawlStarting += (sender, e) => | ||
{ | ||
Console.WriteLine($"Crawling {e.Target.Url}"); | ||
}; | ||
|
||
spider.PageCrawled += (sender, e) => | ||
{ | ||
Console.WriteLine($"Crawled {e.Target.Url}"); | ||
}; | ||
|
||
spider.PageCrawlFailed += (sender, e) => | ||
{ | ||
Console.WriteLine($"Failed to crawl {e.Target.Url}"); | ||
}; | ||
|
||
for(var i = 0; i < 10; i++) | ||
{ | ||
spider.AddTarget("http://example.com"); | ||
} | ||
|
||
await spider.StartAsync(); | ||
|
||
Console.WriteLine("Press any key to exit"); | ||
|
||
Console.ReadKey(); | ||
} | ||
} |