小编Dan*_*iel的帖子

等待后不执行C#控制台应用程序代码

我试图做一个webscraper,从html文件中获取css / js / images的所有下载链接。

问题

第一个断点确实命中,但第二个断点未命中“ Continue”之后。

在Visual Studio中的图片

我正在谈论的代码:

  private static async void GetHtml(string url, string downloadDir)
    {

        //Get html data, create and load htmldocument 
        HttpClient httpClient = new HttpClient();

        //This code gets executed
        var html = await httpClient.GetStringAsync(url);

        //This code not
        Console.ReadLine();
        var htmlDocument = new HtmlDocument();
        htmlDocument.LoadHtml(html);

        //Get all css download urls
        var linkUrl = htmlDocument.DocumentNode.Descendants("link")
            .Where(node => node.GetAttributeValue("type", "")
            .Equals("text/css"))
            .Select(node=>node.GetAttributeValue("href",""))
            .ToList();

        //Downloading css, js, images and source code
        using (var client = new WebClient()) …
Run Code Online (Sandbox Code Playgroud)

c# html-parsing async-await html-agility-pack

1
推荐指数
1
解决办法
594
查看次数

标签 统计

async-await ×1

c# ×1

html-agility-pack ×1

html-parsing ×1