title: Using an if loop to exclude entries containing a substring
body: <p>I'm trying to scrape the results &amp; statistics from the last 4 seasons of snooker from <a href="https://cuetracker.net" rel="nofollow noreferrer">https://cuetracker.net</a>.</p>
  
  <p>I succeeded (somewhat) in scraping most of the data however I neglected to recognise that there are walkovers included. These walkovers contain only nationality,player name and score data and no stats and therefore as I have scraped my data in lists they do not correctly align when I convert them into a DataFrame.</p>
  
  <p>I am trying to use a if in statement in my loop in order to try and skip these matches that are walkovers and therefore realign the correct stats with the correct match. I'm trying to use the word 'Walkover' to stop the item being appended to my list.</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
  from selenium.webdriver.support.select import Select
  from bs4 import BeautifulSoup
  
  import os
  import re
  import time
  import pandas as pd
  
  
  def wait_for_page_load():
      timer = 15
      start_time = time.time()
      page_state = None
      while page_state != 'complete':
          time.sleep(0.5)
          page_state = browser.execute_script('return document.readyState;')
          if time.time() - start_time &gt; timer:
              raise Exception('Timeout :(')
  
  
  chrome_path = r"C:\Users\George\Desktop\chromedriver.exe"
  browser = webdriver.Chrome(chrome_path)
  page_source = browser.page_source
  
  browser.get("https://cuetracker.net/seasons")
  links = browser.find_elements_by_css_selector("table.table.table-striped a")
  hrefs=[]
  for link in links:
      hrefs.append(link.get_attribute("href"))
  
  hrefs = hrefs[1:2]
  
  hrefs2 = []
  
  for href in hrefs:
      browser.get(href)
      wait_for_page_load()
      links2 = browser.find_elements_by_xpath('.//tr/td[2]/a')
      for link in links2:
          hrefs2.append((link.get_attribute("href")))
  
  player_1_nationality = []
  player_1_name = []
  player_1_score = []
  player_2_score = []
  player_2_nationality = []
  player_2_name = []
  date_played = []
  player_1_points_scored = []
  player_2_points_scored = []
  player_1_fifty_plus_breaks = []
  player_2_fifty_plus_breaks = []
  match_progress = []
  player_1_points_per_frame = []
  player_2_points_per_frame = []
  
  
  for href in hrefs2:
      browser.get(href)
      wait_for_page_load()
      list_1_nationality= browser.find_elements_by_xpath('.//div/div[2]/div[1]/b/img')
      for lis in list_1_nationality:
          player_1_nationality.append(lis.get_attribute("alt"))
      list_1_player = browser.find_elements_by_xpath('.//div/div[2]/div[1]/b/a')
      for li in list_1_player:
          player_1_name.append(li.get_attribute('text'))
      list_2_nationality = browser.find_elements_by_xpath('.//div/div[2]/div[3]/img')
      for nationality_2 in list_2_nationality:
          player_2_nationality.append(nationality_2.get_attribute("alt"))
      list_2_name = browser.find_elements_by_xpath('.//div/div[2]/div[3]/a')
      for name_2 in list_2_name:
          player_2_name.append(name_2.get_attribute('text'))
      list_1_score = browser.find_elements_by_xpath('.//div/div[2]/div[2]/span[1]/b')
      for score in list_1_score:
          player_1_score.append(score.get_attribute('innerText'))
      list_2_score = browser.find_elements_by_xpath('.//div/div[2]/div[2]/span[3]')    
      for score_2 in list_2_score:
          player_2_score.append(score_2.get_attribute('innerText'))
      #list_date_played = browser.find_elements_by_xpath('.//div[4]/div[2]/div/div') 
      #for date in list_date_played:
          #date_played.append(date.get_attribute('innerText'))
      page_source = browser.page_source
      soup = BeautifulSoup(page_source, 'lxml')
      points_scored_elem = soup.find_all('div', text='Points Scored') 
      for elem in points_scored_elem:
          player_1_points_scored.append(elem.find_next('div').find_next('div').find_next('div').get_text())
      points_scored_2_elem = soup.find_all('div', text='Points Scored') 
      for elem in points_scored_2_elem:
          player_2_points_scored.append(elem.find_next('div').find_next('div').find_next('div').find_next('div').get_text())
      fifty_plus_breaks_elem = soup.find_all('div', text='50+ Breaks') 
      for elem in fifty_plus_breaks_elem:
          player_1_fifty_plus_breaks.append(elem.find_next('div').find_next('div').find_next('div').get_text())
      fifty_plus_breaks_2_elem = soup.find_all('div', text='50+ Breaks') 
      for elem in fifty_plus_breaks_2_elem:
          player_2_fifty_plus_breaks.append(elem.find_next('div').find_next('div').find_next('div').find_next('div').get_text())
      match_progress_elem = soup.find_all('div', text='Match progress') 
      for elem in match_progress_elem:
          match_progress.append(elem.find_next('div').find_next('div').find_next('div').get_text(strip=True))
      points_per_frame_elem = soup.find_all('div', text='points/frame') 
      for elem in points_scored_elem:
          player_1_points_per_frame.append(elem.find_next('div').find_next('div').find_next('div').get_text())
      points_per_frame_2_elem = soup.find_all('div', text='Avg. points/frame') 
      for elem in points_scored_elem:
          player_2_points_per_frame.append(elem.find_next('div').find_next('div').find_next('div').find_next('div').get_text())
      points_scored_2_elem = soup.find_all('div', text='Avg. points/frame') 
      for elem in points_scored_2_elem:
          player_2_points_per_frame.append(elem.find_next('div').find_next('div').find_next('div').find_next('div').get_text())
      list_date_played = soup.find_all('div', text='Played on') 
      for date in list_date_played:
          date_played.append(date.find_next('div').find_next('div').find_next('div').get_text(strip=True))
  
  </code></pre>
  
  <p>The above code is the bulk of my scraping code. Below is what I'm trying to test in order to skip the walkovers. I'm trying to use the parent of the img as it includes the 'Walkover' string within it's innerText.</p>
  
  <pre><code>for href in hrefs2:
      browser.get(href)
      wait_for_page_load()
      page_source = browser.page_source
      list_3_nationality = browser.find_elements_by_xpath('.//div/div[2]/div[1]/b/img')
      for lis in list_1_nationality:
          check = lis.find_element_by_xpath(("./parent::b"))
          check = check.get_attribute('innerText')
          if 'Walkover' in check:
              continue
          else:
              player_1_nationality.append(lis.get_attribute('alt'))
  
  </code></pre>
  
  <p>For some reason this doesn't seem to be working?</p>