Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting nodes with a specific class #31

Open
RachidTagzen opened this issue Mar 9, 2017 · 5 comments
Open

Getting nodes with a specific class #31

RachidTagzen opened this issue Mar 9, 2017 · 5 comments

Comments

@RachidTagzen
Copy link

Hi,

I want to get all nodes with a class containing (not matching exactly) a specific value.
I used 'find', but it returns only the nodes with class matching exactly the value.
For example, if I have a:

<div class="the-doc the-row'">
      Hello world
</div>

This do not work:

    CSelection c = doc.find("div[class=' the-row']");
    for (int i = 0; i < c.nodeNum(); i++) {
        qDebug() << c.nodeAt(i).text().c_str();
    }

this works:

    CSelection c = doc.find("div[class='the-doc the-row']");
    for (int i = 0; i < c.nodeNum(); i++) {
        qDebug() << c.nodeAt(i).text().c_str();
    }

Thanks.

@TechnikEmpire
Copy link

IIRC, this is one of dozens of bugs. However, you might try getting rid of the space in your not-working example:

CSelection c = doc.find("div[class=' the-row']");

Should be:

CSelection c = doc.find("div[class='the-row']");

@TechnikEmpire
Copy link

On second thought you're not even doing a class selector correctly. See source here.

Class selector should be ".the-row". You're doing an attribute selector, which is requiring a full, complete match.

@RachidTagzen
Copy link
Author

RachidTagzen commented Mar 9, 2017

@TechnikEmpire
That's working now.
Oddly, I have tried the correct Selector way in the past without a good results, and it works now. I don't know why!!

I have an other question: it is possible to match 2 or more conditions with 'find'?
e.g: finding the nodes with: class="the-row" And/Or href="http://www.exampe.com"

Thank you.

@TechnikEmpire
Copy link

You should be able to run basically any css3 selector. Google how to compose such selectors and they should work. I rewrote this library quite a while ago and there are a lot of bugs that cause certain selectors and other things to fail, but I can't remember them all. So you may find that perfectly valid selectors fail or give improper results. If your code is remotely critical, write some tests to verify it because I'd bet my bottom dollar they're not all going to work correctly. It's not the author of this port's fault either, a great many of the bugs were ported over from cascadia, the original source.

@RachidTagzen
Copy link
Author

Thank you for explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants