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

Error when a selector ID includes a space #51

Open
bereddy opened this issue Aug 6, 2022 · 3 comments
Open

Error when a selector ID includes a space #51

bereddy opened this issue Aug 6, 2022 · 3 comments

Comments

@bereddy
Copy link

bereddy commented Aug 6, 2022

The stock quote in the HTML for this page,

https://www.google.com/finance/quote/TCAP:BKK

is within the following div :

<div class="YMlKec fxKbKc">
฿38.50
</div>

If I try to extract the content of this div using htmlq and a command like:

curl -X 'GET' 'https://www.google.com/finance/quote/TCAP:BKK?hl=en'| htmlq div[class="YMlKec fxKbKc"] --text

I get the following error:

thread 'main' panicked at 'Failed to parse CSS selector: ()', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/htmlq-0.4.0/src/main.rs:248:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After trying to extract the stock quote with htmlq using approaches that use the same selector, but in different ways, it's pretty clear to me that htmlq doesn't work right when the selector ID has a space in it.

Or am I missing something?

@ltgustavsen
Copy link

You need to escape the space in the class. "YMlKec\ fxKbKc"
Like this:
curl -s -X 'GET' 'https://www.google.com/finance/quote/TCAP:BKK?hl=en'| htmlq div[class="YMlKec\ fxKbKc"] --text
฿50.00

@XLTechie
Copy link

XLTechie commented Mar 18, 2024 via email

@dmland
Copy link

dmland commented Aug 21, 2024

Moreover, an ID (per the title) should never have spaces. That's not to say that someone hasn't foolishly created HTML with spaces in the ID attribute, but it's counter to the standard.

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

4 participants