How to extract html li tags

Viewed 57

I want to extract that specific "English" text under (li-label-span) tags. How should I do that with beautifulsoup? if anyone is here to help...can you write me some code for this specific problem?

<div class="biblio-info-wrap">
                <h2 class="biblio-title">
                    Product details</h2>
                <ul class="biblio-info">

                    <li>
                            <label>Publication date</label>
                            <span itemprop="datePublished">18 Feb 2021</span>
                        </li>
                   
                    <li>
                            <label>Publication City/Country</label>
                            <span>
                                Edinburgh, United Kingdom</span>
                        </li>
                    ***<li>
                            <label>Language</label>
                            <span>
                                English</span>
                        </li>***
                    <li>
                            <label>Edition Statement</label>
                            <span>Main</span>
                        </li>
                    <li>
                            <label>ISBN10</label>
                            <span>1786892731</span>
                        </li>
    
                    </ul>
            </div>
2 Answers

If html_doc contains the HTML code from your question, you can do:

soup = BeautifulSoup(html_doc, "html.parser")

print(
    soup.find("label", text="Language").find_next("span").get_text(strip=True)
)

Prints:

English

Or using CSS selectors:

print(
    soup.select_one('label:-soup-contains("Language") + span').get_text(
        strip=True
    )
)

import BeautifulSoup

from bs4 import BeautifulSoup

and then

soup = BeautifulSoup(html_doc, "html.parser")
name_tag =soup.find("label", text="Language").find_next("span").get_text(strip=True)
print(name_tag)
Related