May-15-2022, 02:27 PM
from bs4 import BeautifulSoup html = '''\ <li> <span class="a-list-item"> <span class="a-text-bold"> Publisher </span> <span> Springer; 1st ed. 2020 edition (April 27, 2020) </span> </span> </li> <li> <span class="a-list-item"> <span class="a-text-bold"> Publication date </span> <span> April 27, 2020 </span> </span>''' soup = BeautifulSoup(html, 'lxml')
>>> tag = soup.find('span', class_="a-list-item") >>> tag.find_all('span')[0].text.strip() 'Publisher' >>> tag.find_all('span')[1].text.strip() 'Springer; 1st ed. 2020 edition (April 27, 2020)Also remember that BS support CSS Selectors .
>>> tag = soup.select_one('span > span:nth-child(2)') >>> tag.text.strip() 'Springer; 1st ed. 2020 edition (April 27, 2020)'This is what i use most,as when look in browser(inspect) can copy Selector then get the path as show here automatically.