Giter VIP home page Giter VIP logo

Comments (12)

BarryThrill avatar BarryThrill commented on May 31, 2024 1

Hello @Thewildweb !

Just curious. I tried to reproduce the issue you had by doing:

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import requests
from selectolax.parser import HTMLParser

response = requests.get("https://edition.cnn.com/")
bs4 = HTMLParser(response.text)

test= bs4.css_first("span[itemprop='example")
print(test)

and the return was:

  File "selectolax\parser.pyx", line 101, in selectolax.parser.HTMLParser.css_first
  File "selectolax\node.pxi", line 458, in selectolax.parser.Node.css_first
  File "selectolax\node.pxi", line 441, in selectolax.parser.Node.css
  File "selectolax\selector.pxi", line 16, in selectolax.parser.Selector.__init__
  File "selectolax\selector.pxi", line 57, in selectolax.parser.Selector._prepare_selector
ValueError: Bad CSS Selectors: span[itemprop='example

Also if you actually do write a correct example:

bs4.css_first("span[itemprop='example'")

None

Im not quite sure how you were able to produce this bug but it is very intersting for me to know as I might had a similar issue. Wasn't sure if its related to the same thing however.

from selectolax.

rushter avatar rushter commented on May 31, 2024 1

@lexborisov Thanks!

from selectolax.

Thewildweb avatar Thewildweb commented on May 31, 2024

Hi, sorry for the late reply. Here is an exaple.

import requests
from selectolax.parser import HTMLParser

resp = requests.get("https://www.python.org/")
tree = HTMLParser(resp.text)

# bad css selector 'href' between quotes
a_hrefs = tree.css("a['href']")
# now it hangs indefinitly

from selectolax.

BarryThrill avatar BarryThrill commented on May 31, 2024

Hi, sorry for the late reply. Here is an exaple.

import requests
from selectolax.parser import HTMLParser

resp = requests.get("https://www.python.org/")
tree = HTMLParser(resp.text)

# bad css selector 'href' between quotes
a_hrefs = tree.css("a['href']")
# now it hangs indefinitly

I see! That's probably due to incorrect css selector. Could agree that it is not good and should trigger a exception, there is a way to avoid that by doing

a_hrefs = tree.css('a[href^=""')

even though im not expert with css selectors :D

from selectolax.

rushter avatar rushter commented on May 31, 2024

We need to fix this in Modest.
It hangs when parsing a CSS selector.

https://github.com/lexborisov/Modest/blob/393338d994c921705ff71dfbd1d98ceb31328f14/source/mycss/selectors/init.c#L153

from selectolax.

BarryThrill avatar BarryThrill commented on May 31, 2024

https://github.com/lexbor/lexbor - I assume Modest wont be prio anymore? Seems like the dev is working on something new. Have you seen it?

from selectolax.

rushter avatar rushter commented on May 31, 2024

https://github.com/lexbor/lexbor - I assume Modest wont be prio anymore? Seems like the dev is working on something new. Have you seen it?

It's a faster engine, but it does not support everything that we need yet. For example, CSS engine can only parse queries. It can't execute them yet.

Does it only happen when using CSS selector?

It hangs on some malformed examples, but I don't know why this happens. I'm not very familiar with the source code of Modest.

from selectolax.

BarryThrill avatar BarryThrill commented on May 31, 2024

https://github.com/lexbor/lexbor - I assume Modest wont be prio anymore? Seems like the dev is working on something new. Have you seen it?

It's a faster engine, but it does not support everything that we need yet. For example, CSS engine can only parse queries. It can't execute them yet.

Does it only happen when using CSS selector?

It hangs on some malformed examples, but I don't know why this happens. I'm not very familiar with the source code of Modest.

Thank you for the information :) I see. Maybe soon it will support it but even though this is already pretty fast so excited to see if it can be even faster;

from selectolax.

Thewildweb avatar Thewildweb commented on May 31, 2024

It is not a huge issue. I thought it would be nice to throw an exception if it was an easy job.

A, even faster parser would be awesome. I'm coming from bs4, so selectolax feels instant...

from selectolax.

lexborisov avatar lexborisov commented on May 31, 2024

Hi,

I can deal with this tomorrow lexborisov/Modest#84.

from selectolax.

lexborisov avatar lexborisov commented on May 31, 2024

@rushter

Seems to have fixed in Modest.

from selectolax.

BarryThrill avatar BarryThrill commented on May 31, 2024

https://github.com/lexbor/lexbor - I assume Modest wont be prio anymore? Seems like the dev is working on something new. Have you seen it?

It's a faster engine, but it does not support everything that we need yet. For example, CSS engine can only parse queries. It can't execute them yet.

Does it only happen when using CSS selector?

It hangs on some malformed examples, but I don't know why this happens. I'm not very familiar with the source code of Modest.

Hi man! Just got a comment about new update!

lexbor/lexbor#96 (comment)

Is that something you plan to add to selectolax? 😁

from selectolax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.