本文整理汇总了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))
{
}
}
}
}
}
示例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);
}
}
}