artfuldev
artfuldev

Reputation: 1118

How to get the correct unique selector of a dom element for csquery?

So I'm trying to scrape a webpage with some CC content on it, but I'm unable to zero in on the correct unique selectors to provide for CsQuery. Initially after failed attempts (only 3/11 elements were successfully obtained) using Google Chrome, IE 11 and Firefox, I understood CsQuery used Gecko engine. Magically, Firefox, which used Gecko engine itself, didn't give me the correct selectors (again the 3/11 scenario). So I tried to dig deeper. The Gecko engine validator update for CsQuery was released May 15, 2013. So I searched for the firefox version at that time (which was 21, released May 14, 2013). I used it, only to be disappointed with the same results. (3/11)

So, how do you get the correct unique selector for your projects? Any tips would help me, I've been running around this problem for about two weeks now. I can give the url and my requirements if that is absolutely necessary, but I would prefer not to.

What I mean by 3/11 elements obtained:

CQ somePage = CQ.CreateFromUrl(someUrlHereAsString);
String someQuery1 = "div someTag:nth-child(1) someOtherTag";
String someQuery2 = "div someOtherTagNotUsedBefore";
CQ someDom = somePage[someQuery1];
CQ someOtherDom = somePage[someQuery2];

Now, if someDom is null and someOtherDom has a valid csquery DOM element, I say 1/2 elements successfully obtained.

Upvotes: 1

Views: 531

Answers (1)

sm.abdullah
sm.abdullah

Reputation: 1802

may be outdated... You really need a SelectorGadget a chrome extension which quickly generates the css selector. and very helpful with csquery for generating unique and required css selectors. and you can write a web scraper by using both of these tools quickly.

Upvotes: 0

Related Questions