簡體   English   中英

使用Python + Selenium WebDriver選擇一個段落

[英]Select a paragraph with Python + Selenium WebDriver

如何使用Python + Selenium選擇段落? 我在網站的輸入中進行搜索,當我的API返回我的產品后,我想單擊某些產品,但是,它們都是在div中以相同的類呈現的,因為它是在應用SPA,如何通過單擊產品標題的段落來選擇產品,並且它們都具有相同的類?

from selenium import webdriver
import time

options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(executable_path="./chromedriver")
driver.get("www.mysite.com.br")

select_button_input = driver.find_element_by_class_name("button-search")

select_input = driver.find_element_by_css_selector("input[type='text']")
select_input.send_keys("Iphone")
select_button_input.click()

以下是我要從網站中選擇的內容: 我的網站包含產品和產品類別中的類

請嘗試此操作。

element=driver.find_element_by_xpath("//p[@class='card-text text-truncate']").text
print(element)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM