using System;
using AngleSharp;
using AngleSharp.Html.Parser;
using System.Net;
using System.Threading.Tasks;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Task t = WebscrapingSample();
}
static async Task WebscrapingSample()
{
var urlstring = "https://usefuledge.com";
WebClient wc = new WebClient();
try
{
string htmldocs = wc.DownloadString(urlstring);
var config = Configuration.Default;
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(req => req.Content(htmldocs));
foreach ( var item in document.QuerySelectorAll("a"))
{
Console.WriteLine(item.TextContent.Trim() + " " + item.GetAttribute("href"));
}
}
catch (System.Exception)
{
throw;
}
}
以下のように出力されれば、成功です。
Useful Edge /
Menu
Close
Home /
about me /profile.html
Archives /archives/index.html
仕事の依頼 /appdev.html
お問い合わせ /contact.html
ExecNoteでNodeJSコードスニペットを管理しよう /execnote-start-nodejs.html
9月 7, 2020 /execnote-start-nodejs.html
#1-ExecNoteとは?
コメント