title: If condition for adding information into a dataframe
body: <p>I'd need to create a dataframe with the following columns:</p>
  <pre><code>WEB | Country | Organisation
  </code></pre>
  <p>I'm extracting these information from a website: however, there are some webs which do not have any information on the website. This is causing me some issues in updating the dataframe. Unfortunately, the code can work only one website a time, otherwise a captcha appears.
  Please see below the code to have an idea on the individual output:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.by import By
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as EC
  import pandas as pd
  
      element=[]
      organisation=[]
  
      x=['stackoverflow.com'] # ['livevsfox.ca'] I would suggest to try first one, then the other one
  
      frame_dict={}
  
      
      element.append(x) # I am keeping this just because I'd like to consider a for loop in future
      
      chrome_options = webdriver.ChromeOptions()
                  driver=webdriver.Chrome('path')
          
      response=driver.get('website/'+x) # here x should stackoverflow.com, then the other web
      
      try:
      
          wait = WebDriverWait(driver, 30)
          driver.execute_script(&quot;window.scrollTo(0, 1000)&quot;)
          
          try: 
  
              error = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,&quot;section.selection div.container h2&quot;))) # updated after answer from another post and comment below
  
          except: 
              continue
  
          # Country
          c = wait.until(EC.visibility_of_element_located((By.XPATH, &quot;//div[text()='Company data']/../following-sibling::div/descendant::b[text()='Country']/../following-sibling::div&quot;))).text
          country.append(c)   
          
          # Organisation
          try:
              org=wait.until(EC.visibility_of_element_located((By.XPATH, &quot;//div[text()='Company data']/../following-sibling::div/descendant::b[text()='Organisation']/../following-sibling::div&quot;))).text
              organisation.append(org)  
          except: 
              organisation.append(&quot;Data not available&quot;)
  
      except: 
        break
  
      driver.quit()
  
      frame_dict.update({'WEB': element, 'Organisation': organisation, 'Country': country}) 
      df=pd.DataFrame.from_dict(frame_dict)
  </code></pre>
  <p>The code should do the following:</p>
  <ul>
  <li>for <code>x = stackoverflow.com</code> (this is just an example of working url), open chrome; if there is info, then extract information on organisation and country; if there is not, add 'Missing' to the dataframe; exit chrome;</li>
  <li>for <code>x = livevsfox.ca</code>, open chrome; if there is info, then extract information on organisation and country; if there is not, then add 'Missing' in <code>Organisation</code> and <code>Country</code> columns; exit chrome.</li>
  </ul>
  <p>The expected output would be, then:</p>
  <pre><code>WEB                      Country      Organisation
  stackoverflow.com          US       Stack Exchange, Inc.
  livevsfox.ca             Missing       Missing
  </code></pre>
  <p><code>livevsfox.ca</code> returns, in fact, the following message:</p>
  <pre><code>Sorry, livevsfox.ca could not be found or reached (error code 404)
  </code></pre>
  <p>message that does not appear when I look for stackoverflow.com.
  Since stackoverflow.com has Country and Organisation, I can add this info in the dataframe, but I can't do the same for livevsfox.ca .
  I'm thinking a possible solution could be the following:</p>
  <ul>
  <li>check if the <code>h2 class</code> element contains the message above (<code>&quot;Sorry, x could not be found or reached (error code 404)&quot;</code>) : this would mean that the web has no information detected;</li>
  <li>if the web has no information, then add <code>Missing</code> (or <code>NA</code>, up to you) in the dataframe;</li>
  <li>otherwise, the web has information (Owner &amp; Country) to be added in the dataframe.</li>
  </ul>
  <p>I hope you can provide some help.</p>