3

Select one part of text in div class:

<div class="enabled_disabled disabled">
<div class="enabled_disabled">
<div class="enabled_disabled">
<div class="enabled_disabled">
<div class="enabled_disabled disabled">

I have those div tags, is there any xpath syntax or fizzler CSS selectors syntax to select just those div tags which have enabled_disabled only (the 3 in the middle)? not those with enabled_disabled disabled

var html = new HtmlDocument();
html.LoadHtml(getitems);

var doc = html.DocumentNode;
var items = (from r in doc.QuerySelectorAll("div.enabled_disabled:not(.disabled)")
    let Name = r.InnerHtml//QuerySelector("div.enabled_disabled div.title_bar div.rate_title span.name").InnerText.CleanInnerText()
    select new {
        CName = Name
    }).ToArray();
3
  • 1
    what you want exactly? Commented Jul 8, 2014 at 8:27
  • I am not sure if I understood correctly, but you could see this post for getting the class name: stackoverflow.com/questions/22004818/… Commented Jul 8, 2014 at 8:28
  • @bluewonder - Look at other answers also may be it is help you Commented Jul 8, 2014 at 8:52

3 Answers 3

11

Fizzler

To select an element with only the class enabled_disabled, you would use:

[class='enabled_disabled']

Using a :not selector is not available in vanilla Fizzler, but can be used if you grab FizzlerEx

XPath

To select an element with only the class enabled_disabled, you would use:

div[@class='enabled_disabled']

In plain old CSS

If the div's assigned classes starts with enabled_disabled:

div[class^=enabled_disabled ]

If the div's assigned classes contains enabled_disabled

div[class*=enabled_disabled ]

If the div only has the class enabled_disabled

div[class=enabled_disabled ]

If the div has the class enabled_disabled and not the class disabled

div.enabled_disabled:not(.disabled)

Given the HTML you list in your question, either of the last two will work for you.

more on attribute selectors from MDN, and, more on :not()

Sign up to request clarification or add additional context in comments.

9 Comments

SO should provide answers to be marked as favorites, rather than questions.. +1.
Thanks for you reply, However, I tried those last 2 with doc.QuerySelectorAll (Fizzler) and doc.SelectNodes (XPATH) and I have the errors as following: Xpath : ExceptionMessage: "'div.enabled_disabled:not(.disabled)' has an invalid token." and Fizzler : ExceptionMessage: "Unknown functional pseudo 'not'. Only nth-child and nth-last-child are supported."
The OP ask only the 3 in the middle elemnets should be select
@SW4 Yes I tried div[class='enabled_disabled'] and both div.enabled_disabled but it return all the div which includes also the (disabled) standing alone
re: code.google.com/p/fizzler/issues/detail?id=33, any way you would consider using FizzlerEx?fizzlerex.codeplex.com
|
1

You could use this selector that will match the class and will avoid the other.

$(".enabled_disabled:not('.disabled')");

and you can take out contents out of $()

and it is valid css selector

 .enabled_disabled:not(.disabled)

Comments

0

Use not() selector in css.The :not pseudo-class represents an element that is not represented by its argument.

.enabled_disabled:not(.disabled){


}

FIDDLE

More about

SEE THE LINK

3 Comments

The OP is after XPath / Fizzler, :not isnt supported
@SW4 Yes, Im using Xpath / Fizzler and this is the error message that I have : Message: "An error has occurred.", ExceptionMessage: "'.enabled_disabled:not(.disabled)' has an invalid token.", ExceptionType: "System.Xml.XPath.XPathException",
I also tried div[@class='enabled_disabled'] but it returns all the div tags @Sudharsan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.