You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Best practice using selectolax together with if and dict #65
I been using selectolax for a while and also hoping that you are having it well.
I came here not with an issue but rather than a best practice in my situation and I wonder how I could improve my knowledge regarding selectolax. I have written an example code of where I do a requests to a webpage -> Check if the response is 200 and whenever that is, I do another check to see if that value has already been stored -> if not then I would like to get some data from the webpage and in the future I will return the dict with stored parse.
This is what I have written and my concern is that maybe it is not a good idea to do perhaps a if statement to see whenever its there or not and also if its good to do that way when scraping the data and inserting it to a dict? My main goal is to have the fastest speed to get the data
Please feel free to close this ticket if you feel like its abit too off-topic :D
I think using .attrs instead of .attributes can be a little bit faster since it does not retrieve all the attributes. But the difference should be very small.
So, try .attrs.get('href') instead of .attributes().get('href').
I think using .attrs instead of .attributes can be a little bit faster since it does not retrieve all the attributes. But the difference should be very small.
So, try .attrs.get('href') instead of .attributes().get('href').
Appreciate that! I believe there isn't much other stuff to improve? What Im thinking maybe what could happend if the "text()" is not found - I believe that throws an exception but then that shouldn't happen whenever there is response 200 either way.
Thank you so much! You can close if you feel that there isn't other things to improve!
Repository owner locked and limited conversation to collaborators on Aug 23, 2022
Activity
rushter commentedon Aug 19, 2022
I think using
.attrsinstead of.attributescan be a little bit faster since it does not retrieve all the attributes. But the difference should be very small.So, try
.attrs.get('href')instead of.attributes().get('href').BarryThrill commentedon Aug 19, 2022
Appreciate that! I believe there isn't much other stuff to improve? What Im thinking maybe what could happend if the "text()" is not found - I believe that throws an exception but then that shouldn't happen whenever there is response 200 either way.
Thank you so much! You can close if you feel that there isn't other things to improve!