如何使用 Selenium driver.find_elements_by_xpath 提取位置名称。没有 return 数据。正在尝试打印 Tit Heng Phone 商店

How to extract the name of the location with Selenium driver.find_elements_by_xpath. There is no return data. Trying to print out Tit Heng Phone Shop

这是我尝试做的:

import selenium 
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
import pandas as pd

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.yes.com.kh/support/find-shop')
#driver.ge`enter code here`t('https://hoopshype.com/salaries/players/')
#driver = webdriver.Chrome('/Users/syais/AppData/Local/Programs/Python/Python38/Scripts/')

location = driver.find_elements_by_xpath('//div[@class="d-title"]')
print(location)

#它returns空值

inspect website

要获得 title of al phone shop induce WebDriverWait() 并等待 presence_of_all_elements_located() 并获取文本使用 element.get_attribute("textContent")

driver.get("https://www.yes.com.kh/support/find-shop")
locations=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.XPATH,'//div[@class="item blog"]//div[@class="d-title"]')))
for location in locations:
    print(location.get_attribute("textContent"))

导入以下库。

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

控制台输出:

Tit Heng Phone Shop
Nina2 Phone Shop
G B Phone Shop
Rathana Phone Shop
Chet Traprek Hou Phone Shop
Siv Heng Phone Shop
D Na Phone Shop
Heang Heang 2 Phone Shop
Rayuth Phone Shop
Virak Phone Shop
yes hub Sihanoukville
yes hub Sihanouk Ville International Airport
Kim Nai Houy
Kim Sreng phone shop
Por Sokleng
yes hub Battambang
Yorn Kim Err Phone Shop
Yorn Bunyan
Yon Hour Phone Shop
Yin Fuoy Phone Shop
yes hub Poipet
yes hub Serei Sorphorn
Sam Sophea
Kheang Lyhour
Rith Sovann
yes hub siem reap
yes hub Siem Reap International Airport
Vannak Phone Shopp
Rattanak Phone Shop
Hun Rithy Phone Shop
yes hub kep
yes hub takeo
yes hub kampong speu
Khoun Phalla Phone Shop
Pheng Nai phone shop
Pheng Chhunleng phon shop
Cheang Srong phone shop
yes hub Kampot
Thov Vannarith
Preap Samphors
yes hub kampong cham
Pea Vibuth Phone shop
Oeng Sopanha Phone Shop
Sorn Naro phone shop
Ka tangkea phone shop
yes hub pursat
yes hub svay rieng
Kim Veasna phone shop
Lim Sorphorn phone shop
Mao Sithan phone shop
Yuk Samorn phone shop
yes hub koh kong
yes hub pailin
Veng Hong 2 Phone Shop
Veasna Phone Shop
Van Seam Phone Shop
Srey Neth Phone Shop
yes hub Kampong Thom
yes hub Kampong Chhnang
yes hub prey veng