Pracuję w Pythonie z Selenem. Chcę wyodrębnić wszystkie elementy na stronie, ale ma stype, a nie klasę ani identyfikator. Używam następującego kodu:

driver.findElement("By.xpath(//div[style='background: rgb(255, 255, 255); border-radius: 1rem; padding: 0px 1.25rem; margin-top: 1.25rem; margin-bottom: 3rem;']")

Ale to daje mi błąd:

AttributeError: 'WebDriver' object has no attribute 'findElement'

Oto kod źródłowy:

<div style="background: rgb(255, 255, 255); border-radius: 1rem; padding: 0px 1.25rem; margin-top: 1.25rem; margin-bottom: 3rem;"><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/43.png" style="width: 24px; height: 24px; margin-right: 15px;">ახალი ხორცი და ხორცპროდუქტი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/13.png" style="width: 24px; height: 24px; margin-right: 15px;">ახალი ბოსტნეული<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/12.png" style="width: 24px; height: 24px; margin-right: 15px;">ახალი ხილი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/38.png" style="width: 24px; height: 24px; margin-right: 15px;">რძის ნაწარმი და კვერცხი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/26.png" style="width: 24px; height: 24px; margin-right: 15px;">ყველი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/30.png" style="width: 24px; height: 24px; margin-right: 15px;">პური<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/253.png" style="width: 24px; height: 24px; margin-right: 15px;">საკონდიტრო<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/41.png" style="width: 24px; height: 24px; margin-right: 15px;">მზა კერძები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/591.png" style="width: 24px; height: 24px; margin-right: 15px;">გუდვილის რეცეპტები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/33.png" style="width: 24px; height: 24px; margin-right: 15px;">ახალი თევზი და ზღვის პროდუქტი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/32.png" style="width: 24px; height: 24px; margin-right: 15px;">ბაკალეა<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/27.png" style="width: 24px; height: 24px; margin-right: 15px;">ტკბილეული და სასუსნავი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/31.png" style="width: 24px; height: 24px; margin-right: 15px;">გაყინული პროდუქტი<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/29.png" style="width: 24px; height: 24px; margin-right: 15px;">უალკოჰოლო სასმელები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/34.png" style="width: 24px; height: 24px; margin-right: 15px;">ალკოჰოლური სასმელები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/308.png" style="width: 24px; height: 24px; margin-right: 15px;">საკანცელარიო და სათამაშოები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/42.png" style="width: 24px; height: 24px; margin-right: 15px;">ბავშვთა კვება და მოვლა<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/24.png" style="width: 24px; height: 24px; margin-right: 15px;">ჰიგიენა<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/28.png" style="width: 24px; height: 24px; margin-right: 15px;">სახლის მოვლა<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/25.png" style="width: 24px; height: 24px; margin-right: 15px;">ცხოველთა&nbsp;კვება&nbsp;და&nbsp;მოვლა<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/40.png" style="width: 24px; height: 24px; margin-right: 15px;">ელექტრო ნივთები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/37.png" style="width: 24px; height: 24px; margin-right: 15px;">სადღესასწაულო ნივთები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p><p style="margin: 0px; padding: 1.125rem 0px; font-size: 0.875rem; display: flex; align-items: center; border-bottom: 1px solid rgb(241, 241, 245);"><img src="/icons/shop/5/447.png" style="width: 24px; height: 24px; margin-right: 15px;">Home Cooking Adventures - რეცეპტები<span style="margin-right: 0.5rem; font-size: 1rem; margin-left: auto;"><i class="icon-chevron-right" style="font-size: 0.75rem; color: rgb(0, 150, 108);"></i></span> </p></div>

Oto link strony i elementu, który chcę kliknąć: https://moitane.ge/shop/5-gudvili/ 43-AXALI-XORCI-DA-XORCPRODUQTI Wprowadź opis obrazu tutaj

1
shorena tevzadze 21 marzec 2021, 20:08

1 odpowiedź

Najlepsza odpowiedź

Selen WebDriver w Pythonie nie ma metody .

To ma:

 driver.find_element(By.XPATH, 'your xpath')

Spróbuj sprawdzić wszystkie metody za pomocą:

print(dir(driver))

Wypróbuj kod:

import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://moitane.ge/shop/5-gudvili/43-axali-xorci-da-xorcproduqti")
time.sleep(3)
el = driver.find_element(By.XPATH, "//div[@class='style__ShopProductSubCategoryChip-sc-1bc3ssb-2 iKSeHs']")
el.click()
time.sleep(3)
driver.quit()
0
Vova 21 marzec 2021, 18:44