The table on the site may have a row

<div class="emptyData">Праздничный день</div> 

or

 <a class="strong " title="Технология" href="https://">Технология</a> 

How can bs4 handle both values? My code is as follows

 for x in row: i = 0 list = x.find_all('a', {'class':'strong'}) 

How to supplement it?

    1 answer 1

    Try to do as in the following example:

     import requests import bs4 url = 'http://www.garant.ru/company/garant-press/ab/217886/03/' r = requests.get(url) soup = bs4.BeautifulSoup(r.content, 'html.parser') found = soup.find_all(['a', 'div'], {'class':['buy-garant', 'controls']}) print(found) 

    Result:

     [<a class="buy-garant" href="http://aero.garant.ru/?utm_source=garant&amp;utm_medium=buttom&amp;utm_content=buy-garant&amp;utm_campaign=knop ka-v-shapke#form_title" title="Купить ГАРАНТ"><span></span>Купить ГАРАНТ</a>, <div class="controls"> <input id="pers_login" name="uname" type="text" value=""> <p class="error-msg" id="error_login"> </p> </input></div>, <div class="controls"> <input id="pers_password" name="upass" type="password" value=""> <p class="error-msg" id="error_password"> </p> </input></div>]