Traverse the dom with CsQuery

无人久伴 提交于 2019-12-06 14:15:16
List<string> artists = html[".featured .artist a"].Select(dom=>dom.TextContent).ToList();

where html == your CQ object.

var odd = row.Cq().Find(".featured odd");

should be

var odd = row.Cq().Find(".featured.odd");

You should try something similar to this:

var html = GetHtml("http://www.allmusic.com/newreleases");
var query = CQ.Create(html)
var row = query[".artist>a"];
string link = row.Attributes["href"];
string text = row.DefaultValue or row.InnerText or row.Value...

CsQuery is port of JQuery so you can google for JQuery code

UPDATE: To traverse to get all artists and titles

var rows = query[".featured odd"];
foreach(var row in rows)
{
  var artistsLink = row[".artists>a"];
  var title = row[".title"];
 // here do whatever you need with this
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!