Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
874 views
in Technique[技术] by (71.8m points)

text in search results with selenium and python

can someone assist me with find out which driver.find_element_by_*** I can use to find the text in this code (I am looking for all of the search results titles that pop up:

from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium import webdriver

driver = webdriver.Chrome(executable_path=
                          r'/home/littlejiver/Downloads/chromedriver_linux64/chromedriver')
driver.get("https://bestbuy.ca/")

wait = WebDriverWait(driver, 10)
wait.until(ec.element_to_be_clickable((By.XPATH,
                                       '//*[@id="root"]/div/div[4]/header/div/div/div[2]/div/div/div[2]/div/div/form/di'
                                       + 'v/input'))).send_keys("RTX 3060 TI")
wait.until(ec.element_to_be_clickable((By.XPATH,
                                       '//*[@id="root"]/div/div[4]/header/div/div/div[2]/div/div/div[2]/div/div[2]/div/'
                                       + 'ul/li[2]/a'))).click()

# the magic would happen here
results = driver.find_elements_by_class_name('div.a')

for x in results:
    print(x)

and also for bonus points if you know of some guide that may be useful in figuring these sort of question out

Thank you!

littlejiver

question from:https://stackoverflow.com/questions/65889596/text-in-search-results-with-selenium-and-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...