Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to navigate through elements using find or find_all instead of select?

As I know, you can navigate through page’s elements with select method e.g.:

text = soup.select('.css-lw5dil > .css-1p6sxhz')

Is there any way to do so with find method?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

select_one is equal to find and select is equal to find_all or findAll
select_one /find for single element and select/find_all for a list
Yes, you can navigate that but css selector’s locator is more flexible in this case.

text = soup.select('.css-lw5dil > .css-1p6sxhz')

Using soup locator as follows:

text = soup.find('tag name',class_="css-lw5dil").find_all('tag name',class_= "css-1p6sxhz")

Now you can iterate over it like css selector as follows:

for i in text:
    do something new
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading