How to select div by text content using Beautiful Soup?

后端 未结 3 695
轮回少年
轮回少年 2021-02-08 11:20

Trying to scrape some HTML from something like this. Sometimes the data I need is in div[0], sometimes div[1], etc.

Imagine everyone takes 3-5 classes. One of them is al

3条回答
  •  轮回少年
    2021-02-08 11:56

    Another way (using css selector) is:

    divs = soup.select('div:contains("Biology")')

    EDIT:

    BeautifulSoup4 4.7.0+ (SoupSieve) is required

提交回复
热议问题