B
B
badproger12years2019-05-28 12:44:31
Python
badproger12years, 2019-05-28 12:44:31

How to skip None object in BeautifulSoup?

I have a 2gis parser, on the 2gis site there are tags that store don't understand what.
In short, how to skip none object in a loop, how to do it?
the code

## for div in divs:
            ##location = div.find('span', attrs={'class':'mediaMiniCard__address'})
            ##opening_hours = div.find('span', attrs={'class':'mediaMiniCard__opened_opened_tooltip_position_topLeft'})
           
            
         ##   print(location)
          ##  print(opening_hours)
import requests
from bs4 import BeautifulSoup as bs

headers1 = {'accept' : '*/*', 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}
bar_url = 'https://2gis.ru/kaluga/search/%D0%B1%D0%B0%D1%80?queryState=center%2F36.271892%2C54.523258%2Fzoom%2F11';




def g2isBar(bar_url, headers1):
    organization = []
    ses = requests.Session()
    req = ses.get(bar_url, headers = headers1)
    if req.status_code == 200:
        souBar = bs(req.content, 'html.parser')



        divs = souBar.find_all('div', attrs={'class':'online__panels'})
        divscol = souBar.find_all('h2', attrs={'class':'searchBar__mediaTabText'})
        divtitle = souBar.find_all('div', attrs={'class':'mediaMiniCard__body'})
        
        for dive in divtitle:
                     nameCompany = dive.find('h3', attrs={'class':'mediaMiniCard__name'}).text
              ##     nameCompanyLogo = dive.find('h3', attrs={'class' : 'mediaMiniCard__name._hasLogo'})
                     nameOrganizat = dive.find('h4', attrs ={'class':'mediaMiniCard__description'})
                     print(nameOrganizat)
                     print(nameCompany)

                 



          
  
    else:
        print('error')

g2isBar(bar_url, headers1)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question