spooky123
spooky123

Reputation: 153

Using selectors with csQuery

I am very new to csQuery and I am having a difficult time getting off the ground. The following is my simple asp.net controller. It is returning the following: $('.ng-scope').eq(0).find($('.ng-binding')).html(). The classes referenced do exist. Am I doing this right?

 public class HomeController : Controller
{
    ViewModel Vm = new ViewModel();
    public ActionResult Index()
    {
        var url = "http://www.weather.com/weather/5day/l/08817:4:US";
        var web = new WebClient();
        web.Headers[HttpRequestHeader.UserAgent] = "Hello"; //in case they require it
        var html = web.DownloadString(url);
        CQ dom = html;
        var x = dom["$('.ng-scope').eq(0).find($('.ng-binding')).html()"];

        Vm.Day = x.Render();
        return View(Vm);
    }
}

Upvotes: 2

Views: 592

Answers (2)

spooky123
spooky123

Reputation: 153

DWright, you're absolutely correct! After analyzing it again myself, I realized that the classes i'm referring to are dynamically created but don't exist in the source.I'll have to trace the DOM back to the caller and work from there.

Upvotes: 0

DWright
DWright

Reputation: 9500

So, first thing is that you the selector is in jQuery syntax, and needs to be adapted for csQuery, to something like: dom[".ng-scope"].Eq(0).Find(".ng-binding").Html();

Second I put the url in a browser and then looked at the source. There was a not a single element with a class of "ng-scope". So I think you need to analyze the source of the page you are downloading so that you can reformulate the query.

Upvotes: 0

Related Questions