当前位置: 首页>>代码示例>>C#>>正文


C# HtmlDocument.GetResourcesUrls方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.GetResourcesUrls方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.GetResourcesUrls方法的具体用法?C# HtmlDocument.GetResourcesUrls怎么用?C# HtmlDocument.GetResourcesUrls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlDocument的用法示例。


在下文中一共展示了HtmlDocument.GetResourcesUrls方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessPage

        public void ProcessPage(Uri outputFolder, Func<Uri, bool> isLocalUrl, Dictionary<Uri, string> pages, Dictionary<Uri, string> resources, Uri pageUrl, HtmlDocument pageDocument, Logger logger)
        {
            var resourcesUrls = pageDocument.GetResourcesUrls(outputFolder, isLocalUrl, resources, pageUrl);

            using (var webClient = new WebClient())
            {
                foreach (var resourceUrls in resourcesUrls)
                {
                    var localResourcePath = resourceUrls.FilePath.LocalPath;
                    if (!Path.GetExtension(localResourcePath).Equals(".js", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    string errorMessage;
                    if (!VerifyDirectoryExists(Path.GetDirectoryName(localResourcePath), logger, out errorMessage))
                    {
                        continue;
                    }

                    var externsFileName = GetExternsFilePath(localResourcePath);
                    try
                    {
                        webClient.DownloadFile(GetExternsFileUrl(resourceUrls.ResourceUrl), externsFileName);
                    }
                    catch (WebException)
                    {
                        using (File.Create(externsFileName))
                        {
                        }
                    }
                }
            }
        }
开发者ID:bdukes,项目名称:Website-Optimizer,代码行数:34,代码来源:JavaScriptOptimizationProcessor.cs

示例2: GetResources

        private void GetResources(Uri outputFolder, Func<Uri, bool> isLocalUrl, Dictionary<Uri, string> pages, Dictionary<Uri, string> resources, Uri pageUrl, HtmlDocument pageDocument, Logger logger)
        {
            var resourcesUrls = pageDocument.GetResourcesUrls(outputFolder, isLocalUrl, resources, pageUrl);

            using (var webClient = new WebClient())
            {
                foreach (var resourceUrls in resourcesUrls)
                {
                    var localResourcePath = resourceUrls.FilePath.LocalPath;
                    logger.LogDebugMessage("Saving resource {0} to {1}", pageUrl, localResourcePath);

                    string errorMessage;
                    if (!VerifyDirectoryExists(Path.GetDirectoryName(localResourcePath), logger, out errorMessage))
                    {
                        pages[pageUrl] = errorMessage;
                        continue;
                    }

                    webClient.DownloadFile(resourceUrls.ResourceUrl, localResourcePath);

                    resources.Add(resourceUrls.FilePath, null);
                }
            }
        }
开发者ID:bdukes,项目名称:Website-Optimizer,代码行数:24,代码来源:FileOutputProcessor.cs


注:本文中的HtmlAgilityPack.HtmlDocument.GetResourcesUrls方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。