Scraping data inside an iframe with splinter

104 Views Asked by At

Currently using splinter and trying to get some data from this page :

My attempt

iframe = browser.get_iframe('IframeCurrentEcom')

iframe
<contextlib._GeneratorContextManager object at 0x00000210118653A0>

iframe.find_by_xpath("/html/body/div[3]/div[2]/div[1]/form/div[3]/div[1]/div/div/div/div[2]/span[2]")

Output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_GeneratorContextManager' object has no attribute 'find_by_xpath'

I have also tried

>>> with browser.get_iframe('IframeCurrentEcom') as iframe:
...     iframe.find_by_xpath('/html/body/div[3]/div[2]/div[1]/form/div[3]/div[1]/div/div/div/div[2]/span[2]')

Output:

Traceback (most recent call last):
  File "C:\Users\bonva\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\switch_to.py", line 87, in frame
    frame_reference = self._driver.find_element(By.ID, frame_reference)
  File "C:\Users\bonva\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 857, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\bonva\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
  File "C:\Users\bonva\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="IframeCurrentEcom"]
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:186:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.jsm:398:5
element.find/</<@chrome://remote/content/marionette/element.js:300:16

Cannot find element with that id ? Really , here it is a proof that he should be able to find it :

enter image description here

Example (run it on your own)

from splinter import Browser

>>> browser = Browser()
>>> browser.visit("https://www.one-line.com/en")
>>> browser.execute_script("window.scrollTo(0,500)") 
>>> input = browser.find_by_xpath('//*[@id="ctrack-field"]')
>>> input.fill("CAAU4023030")
>>> search = browser.find_by_xpath('/html/body/div[1]/div/main/div[3]/div/div/div/div/div[2]/div/div/div[2]/form/div[2]/button') 
>>> search.click()
>>> browser.get_iframe('IframeCurrentEcom') 
<contextlib._GeneratorContextManager object at 0x000002100F991C40>
>>> iframe = browser.get_iframe('IframeCurrentEcom') 
>>> iframe.html

0

There are 0 best solutions below