【发布时间】:2021-12-08 04:35:39
【问题描述】:
我正在尝试开发一个“机器人”,以便在“zalando”网站上更快地进行购买。 例如,假设我想买这个:https://www.zalando.it/nike-sportswear-air-force-1-07-lv8-sneakers-basse-whiteblackwolf-grey-ni112o0m9-a11.html
我需要一个代码来从菜单中选择鞋码(查看链接或下图),我尝试了“选择”功能:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
from selenium.webdriver.support.ui import Select
#The first thing you’ll want to do with WebDriver is navigate to a link.
#The normal way to do this is by calling get method:
options = Options()
ua = UserAgent()
userAgent = ua.random
print(userAgent)
options.add_argument(f'user-agent={userAgent}')
driver = webdriver.Chrome(options=options)
driver.get("https://www.zalando.it/nike-sportswear-air-force-1-07-lv8-sneakers-basse-
whiteblackwolf-grey-ni112o0m9-a11.html")
#tried this
element = driver.find_element_by_xpath('/html/body/div[7]/div/div[3]')
all_options = element.find_elements_by_tag_name("_7Cm1F9 ka2E9k uMhVZi dgII7d _6yVObe
pVrzNP")
for option in all_options:
print("Value is: %s" % option.get_attribute("value"))
option.click()
#and this:
#select = Select(driver.find_element_by_id('id'))
#select.deselect_all()
element =
driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div/div[2]/div[1]/x-
wrapper-re-1-6/div/div[2]').click
但是 Select 不起作用,我希望有人能解释一下原因。谢谢!
【问题讨论】:
标签: python selenium selenium-webdriver bots