Python 3.x 如何从div类中查找文本

Python 3.x 如何从div类中查找文本,python-3.x,selenium,selenium-chromedriver,Python 3.x,Selenium,Selenium Chromedriver,我试图用Selenium从div类语句中获取文本 from selenium import webdriver import time chrome_path = r"C:\Users\User1\Downloads\chromedriver_win32\chromedriver.exe" driver = webdriver.Chrome(chrome_path) driver.get("https://www.gigantti.fi/cms/gigantti-outlet/gigantti-

我试图用Selenium从div类语句中获取文本

from selenium import webdriver
import time
chrome_path = r"C:\Users\User1\Downloads\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.gigantti.fi/cms/gigantti-outlet/gigantti-outlet/")
time.sleep(10)
posts1 = driver.find_elements_by_class_name('description')
print(posts1)
posts2 = driver.find_elements_by_css_selector('description')
print(posts2)
posts3 = driver.find_elements_by_tag_name('description')
print(posts3)
posts4 = driver.find_elements_by_id('description')
print(posts4)
posts5 = driver.find_elements_by_name('description')
print(posts5)
posts6 = driver.find_elements_by_xpath("//div[@class='description']")
driver.close()
输出是这样的

DevTools listening on ws://127.0.0.1:58551/devtools/browser/4ebf2909-a977-43b8-b0bc-2824c2d371d7
[]
[]
[]
[]
[<selenium.webdriver.remote.webelement.WebElement (session="5a662510a9af8bec45752c91b4397d06", element="6e54f7d0-c586-4f97-a974-1af8d19610ce")>]
DevTools在ws://127.0.0.1:58551/DevTools/browser/4ebf2909-a977-43b8-b0bc-2824c2d371d7上侦听
[]
[]
[]
[]
[]
这是Chrome在检查现场时显示的内容

<div class="description">Samsug HD39J1230GW wifi sovitin, erä</div>
Samsug HD39J1230GW无线sovitin,erä
我试图提取Samsug HD39J1230GW wifi sovitin,erä


这些元素在iframe Name
Gigantti Outlet中提供。您需要先切换到iframe。请尝试下面的代码

诱导
WebDrivberWait
frame\u变为可用,并切换为可用()

诱导位于的所有元素的
WebDrivberWait
可见性()

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 as EC

chrome_path = r"C:\Users\User1\Downloads\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.gigantti.fi/cms/gigantti-outlet/gigantti-outlet/")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"Gigantti Outlet")))
posts1=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,".description")))
for post in posts1:
    print(post.text)