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

Time:12-02

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?

CodePudding user response:

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
  • Related