简体   繁体   English

CSS选择器选择div类名的某些部分

[英]CSS selector select some part of div class name

Select one part of text in div class: 在div类中选择文本的一部分:

<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)? 我有那些div标签,是否有任何xpath语法或fizzler CSS选择器语法只选择那些只有enabled_disabled的 div标签(中间的3)? not those with enabled_disabled disabled 而不是那些禁用enabled_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();

Fizzler Fizzler

To select an element with only the class enabled_disabled , you would use: 要选择具有enabled_disabled类的enabled_disabled ,您将使用:

[class='enabled_disabled']

Using a :not selector is not available in vanilla Fizzler , but can be used if you grab FizzlerEx 使用:not选择器在vanilla Fizzler中不可用 ,但是如果你抓住FizzlerEx就可以使用

XPath XPath的

To select an element with only the class enabled_disabled , you would use: 要选择具有enabled_disabled类的enabled_disabled ,您将使用:

div[@class='enabled_disabled']

In plain old CSS 在普通的旧CSS中

If the div's assigned classes starts with enabled_disabled : 如果div的指定类 enabled_disabled

div[class^=enabled_disabled ]

If the div's assigned classes contains enabled_disabled 如果div的已分配类包含 enabled_disabled

div[class*=enabled_disabled ]

If the div only has the class enabled_disabled 如果div 只有enabled_disabled

div[class=enabled_disabled ]

If the div has the class enabled_disabled and not the class disabled 如果div 具有enabled_disabled 而不 disabled该类

div.enabled_disabled:not(.disabled)

Given the HTML you list in your question, either of the last two will work for you. 鉴于您在问题中列出的HTML,最后两个中的任何一个都适合您。

more on attribute selectors from MDN , and, more on :not() 更多关于来自MDN的属性选择器 ,以及更多关于:not()

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 它是有效的CSS选择器

 .enabled_disabled:not(.disabled)

Use not() selector in css.The :not pseudo-class represents an element that is not represented by its argument. 在css中使用not()选择器。 :not pseudo-class表示不由其参数表示的元素。

.enabled_disabled:not(.disabled){


}

FIDDLE

More about 更多关于

SEE THE LINK 看到链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM