Данные о продукте внутри iframe
Вы можете использовать XPath для поиска:
iframe = driver.find_element_by_xpath("//iframe[@id='ecat']")
Затем переключитесь на:
driver.switch_to.frame(iframe)
Вот как переключиться обратно на содержимое по умолчанию (из):
driver.switch_to.default_content()
Не использовать time-sleep
модуль, попробуйте явное ожидание .
см. разница.
EX:
from scrapy import Spider
from selenium import webdriver
from scrapy.selector import Selector
from scrapy.http import Request
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome('D:\chromedriver_win32\chromedriver.exe')
driver.get('http://www.tesensors.com/global/en/product/inductive-capacitive/xs-xt-ref')
#soemtime the site ask you select language and country so need click button as below
sign_in_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "edit-submit--4")))
sign_in_button.click()
#switch iframe
iframe = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//iframe[@id='ecat']")))
driver.switch_to.frame(iframe)
# scrapy content.total 1168 items, here there is no result.
product_model_name = driver.find_elements_by_xpath('//span[@itemprop="name"]')
print(product_model_name[0].text)
product_desc=driver.find_elements_by_xpath('//span[@itemprop="description"]')
print(product_model_name[0].text)