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

Performance optimization css_first #113

Open
SkySandy opened this issue May 1, 2024 · 0 comments
Open

Performance optimization css_first #113

SkySandy opened this issue May 1, 2024 · 0 comments

Comments

@SkySandy
Copy link

SkySandy commented May 1, 2024

I received statistics on website downloads when using selectolax
The most popular functions were as follows (by total time and number of calls):

  1. css_first (3,2 million calls)
  2. text (2,8 million calls)
    The library tests (at this site) also use "css_first" all the time

I looked at the source text css_first. The function first gets all the nodes on the page and then takes the first node. It takes a very long time. Can you optimize this process?

and another question

This function is called many times within my program:

def first_text(query, deep, default=None)
link = item.css_first(query)
if link is not None:
return link.text(deep=deep, strip=True)
else:
return default

Could you add this function to the class Node (wth self instead of query)? (in all my parsing programs the parameter "strip" has a value True and I don't understand why you set the default value to False)

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

1 participant