title: Access the link inside iframe with Python/Selenium and get url
body: <p>My <strong>main html page</strong> has an iframe it and I to need to get the text <code>Code: LWBAD</code> that lives there.</p>
  
  <p>Check picture for a better understanding:</p>
  
  <p><a href="https://i.stack.imgur.com/DJgbd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DJgbd.png" alt="enter image description here"></a></p>
  
  <p>Bellow is my <strong>main html page source</strong> that has an iframe in it:</p>
  
  <pre><code>&lt;td class="centerdata flag"&gt;&lt;iframe style="width: 200px; height: 206px;" scrolling="no" src="https://www.example.com/test/somewhere" &gt;&lt;/iframe&gt;&lt;/td&gt;
  </code></pre>
  
  <p>The redirect link (iframe page) has this <strong>html source</strong> </p>
  
  <pre><code>&lt;body&gt;
  &lt;a href="http://www.test2.com" target="_blank"&gt;
  &lt;img src="https://img2.test2.com/LWBAD-1.jpg"&gt;&lt;/a&gt;
  &lt;br/&gt;Code: LWBAD
  </code></pre>
  
  <p></p>
  
  <p>So far I can get the complete page source from my <strong>main html page</strong>. </p>
  
  <pre><code>from bs4 import BeautifulSoup
  from selenium import webdriver
  import time
  import html5lib
  
  driver_path = '/usr/local/bin/chromedriver 2'
  driver = webdriver.Chrome(driver_path)
  driver.implicitly_wait(10)
  
  driver.get('http://example.com')
  try:
      time.sleep(4)
      iframe = driver.find_elements_by_tag_name('iframe')
      driver.switch_to_default_content()
  
      output = driver.page_source
  
      print (output)
  
  finally:
      driver.quit();
  </code></pre>
  
  <p>*urls are not accesible from outside of my network that's why I used example.com</p>