title: Web Scraping: Error handling when web page doesn't contain any specific element
body: <p>I've written a Python script for scraping pages for information like Phone Number, Address, Rating, etc. The script is running fine when all the values are available on the page. However, it throws error where there is no specific info like Phone Number is not available. It breaks the loop, what all I want is to skip those pages and continue scraping next pages.</p>
  <p>Below is the sample code to extract phone number:</p>
  <pre><code>def get_phone_number(body):
  i=0
  for item in body.find('p',{'class':'contact-info'}):
      i+=1
      if(i==2):
          phoneNo=''
          try:
              for element in item.find_all(class_=True):
                  classes = []
                  classes.extend(element[&quot;class&quot;])
                  phoneNo+=str((which_digit(classes[1])))
          except:
              pass
          return phoneNo
  </code></pre>
  <p>Above is the function to scrape contact information. Below is the error that I'm facing in the for loop.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-30-bfd4a9d231f1&gt; in &lt;module&gt;()
       20                 dict_service = {}
       21                 name = get_name(service_html)
  ---&gt; 22                 phone = get_phone_number(service_html)
       23                 rating = get_rating(service_html)
       24                 count = get_rating_count(service_html)
  
  &lt;ipython-input-25-7168fec7d0c7&gt; in get_phone_number(body)
       21 def get_phone_number(body):
       22     i=0
  ---&gt; 23     for item in body.find('p',{'class':'contact-info'}):
       24         i+=1
       25         if(i==2):
  
  TypeError: 'NoneType' object is not iterable</code></pre>
  </div>
  </div>
  </p>
  <p>Any sort of help will be much appreciated!!</p>