【发布时间】:2017-01-30 14:54:38
【问题描述】:
我确实使用 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
任何帮助将不胜感激
【问题讨论】:
-
你能发布一个标签来获取 img 值吗?
-
.OfType
() img with calss="_icyx7" 选择源代码 -
您发布了整个标签吗?非常重要的是它之间或命名空间之间是否有空格
-
我正在使用 AngleSharp 来提取具有给定属性的特定标签我没有使用整个标签我只是给出了我想要 Anglesharp 的信息,正如你在我的代码中看到的那样
标签: c# android xamarin anglesharp