title: How to use a conditional statement while scraping?
body: <p>I'm trying to scrape the MTA website and need a little help scraping the "Train Lines Row." (Website for reference: <a href="https://advisory.mtanyct.info/EEoutage/EEOutageReport.aspx?StationID=All" rel="nofollow noreferrer">https://advisory.mtanyct.info/EEoutage/EEOutageReport.aspx?StationID=All</a></p>
  
  <p>The train line information is stored as image files (1 line subway, A line subway, etc) describing each line that's accessible through a particular station. I've had success scraping info out of rows in which only one train passes through, but I'm having difficulty figuring out how to iterate through the columns which have multiple trains passing through it...using a conditional statement to test for whether it has one line or multiple lines. </p>
  
  <pre><code>tableElements = table.find_elements_by_tag_name('tr') 
  </code></pre>
  
  <p>that's the table i'm iterating through   </p>
  
  <pre><code>tableElements[2].find_elements_by_tag_name('td')[1].find_element_by_tag_name('h4').find_element_by_tag_name('img').get_attribute('alt')
  </code></pre>
  
  <p>this successfully gives me the values if only one value exists in the particular column</p>
  
  <pre><code>tableElements[8].find_elements_by_tag_name('td')[1].find_element_by_tag_name('h4').find_elements_by_tag_name('img')
  </code></pre>
  
  <p>this successfully gives me a list of values I can successfully iterate through to extract my needed values. </p>
  
  <p>Now I try and combine these lines of code together in a forloop to extract all the information without stopping. </p>
  
  <pre><code>for info in tableElements[1:]:
   if info.find_elements_by_tag_name('td')[1].find_element_by_tag_name('h4').find_elements_by_tag_name('img')[1] == True:
      for images in info.find_elements_by_tag_name('td')[1].find_element_by_tag_name('h4').find_elements_by_tag_name('img'):
          print(images.get_attribute('alt'))
   else:
      print(info.find_elements_by_tag_name('td')[1].find_element_by_tag_name('h4').find_element_by_tag_name('img').get_attribute('alt'))
  </code></pre>
  
  <p>I'm getting the error message: "list index out of range." I dont know why, as every iteration done in isolation seems to work. My hunch is I haven't correctly used the boolean operation properly here. My idea was that if find_elements_by_tag_name had an index of [1] that would mean multiple image text for me to iterate through. Hence, why I want to use this boolean operation. </p>
  
  <p>Hi All, thanks so much for your help. I've uploaded my full code to Github and attached a link for your reference: <a href="https://github.com/tsp2123/MTA-Scraping/blob/master/MTA.ElevatorData.ipynb" rel="nofollow noreferrer">https://github.com/tsp2123/MTA-Scraping/blob/master/MTA.ElevatorData.ipynb</a></p>
  
  <p>The end goal is going to be to put this information into a dataframe using some formulation of and having a for loop that will extract the image information that I want. </p>
  
  <pre><code>dataframe = []
  for elements in tableElements:
    row = {}
    columnName1 = find_element_by_class_name('td')
    ..
  </code></pre>