我想把这个写在html里
<div id="lyrics-body-text">
<p class='verse'>It's been a long and winding journey<br/>
But I'm finally here tonight picking up the pieces<br/>
And walking back into the night into the sunset of your glory<br/>
When my heart and future lies there's nothing like that feeling<br/>
When I look into your eyes</p></div>使用C#和XAML,我在这里也使用HtmlAGilityPack,我的代码:
HttpClient wClient = new HttpClient();
responseData = await wClient.GetByteArrayAsync(URL);
UTF8Encoding utf8 = new UTF8Encoding();
String Lyrics = utf8.GetString(responseData, 0, responseData.Length);
StringBuilder pureText = new StringBuilder();
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(Lyrics);
try
{
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//div[@id='lyrics-body-text']")) // error
{
pureText.Append(node.InnerText);
}
}
catch
{ }
return pureText.ToString();以下是错误:
'HtmlAgilityPack.HtmlNode‘不包含'SelectNodes’的定义,也找不到接受'HtmlAgilityPack.HtmlNode‘类型的第一个参数的扩展方法'SelectNodes’(您缺少使用指令还是程序集引用?)
发布于 2014-01-17 18:28:30
如果没有看到代码的其余部分,就很难进行测试。但是,尝试用DocumentNode.SelectNodes替换DocumentElement.SelectNodes。
来自HtmlAgilityPack文档示例代码:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"]))
{
HtmlAttribute att = link["href"];
att.Value = FixLink(att);
}
doc.Save("file.htm");https://stackoverflow.com/questions/21192199
复制相似问题