我确实使用webview来获取完整的页面源并将其写入文件
所以现在我需要从文件中提取所有图像
我使用StreamReader读取了文件,然后将其提供给名为TheHtmlSource的字符串,如代码中所示
这是我的代码
var config = Configuration.Default.WithDefaultLoader();
for (int i = 0; i < TheHtmlSource.Length; i++)
{
string theImageUrl = (await BrowsingContext.New(config).OpenAsync(TheHtmlSource))
.DocumentElement.Descendents()
.Where(x => x.NodeType == NodeType.Element)
.OfType<IHtmlImageElement>()
.Where(x => x.Attributes["class"]?.Value == "_icyx7")
.Select(x => x.Attributes["src"]?.Value)
.FirstOrDefault();
int index = theImageUrl.IndexOf("?");
string fixedImageUrl = theImageUrl.Remove(index);
_list.Add(new AllImageUrls()
{
url = fixedImageUrl
});
}
但我不工作,我不断收到NullReference错误
我在Visual Studio中使用Xamarin
任何帮助将不胜感激
await BrowsingContext.New(config).OpenAsync(addressString)
接受一个字符串,它应该是一个地址。根据您的描述,您正在将源字符串传递给此方法,这是无效的。
如果要解析源字符串,可以使用AngleSharp.Parser.Html.HtmlParser
,您可以在AngleSharp Documentation中找到它的用法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句