【发布时间】:2021-04-15 07:15:18
【问题描述】:
我正在尝试通过 python 脚本填写此表单: https://reassurez-moi.fr/devis-assurance-pret-immobilier/60773413ea18bd60703427df9c39cbd2c5c1c8d46fda062f92513e1c266bbfb5
但不幸的是,我找不到允许我从下拉列表中选择值的代码。
您可以注意到,在 html 中,我们没有下拉列表中的不同选项。
你能告诉我如何制作一个可以让我填写此表格的 python 脚本吗?
提前谢谢你。
下面的代码显示了我到目前为止所做的事情,但它不允许我从下拉列表中选择一个值
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
web1 = webdriver.Chrome(ChromeDriverManager().install())
web1.get('https://reassurez-moi.fr/simulation-tarifaire-assurance-habitation?homeType=1')
#time.sleep(2)
topics_xpath = '//*[@id="home-comparator-base"]/div[2]/div/div[2]/div/form/div[1]/div[1]/div/div[1]/div[2]/div/div[2]/button'
WebDriverWait(web1,2).until(expected_conditions.visibility_of_element_located((By.XPATH, topics_xpath)))
Rue_Adresse = "Rue de la Paix"
last = web1.find_element_by_xpath('//*[@id="home-comparator-base"]/div[2]/div/div[2]/div/form/div[3]/div[1]/div[2]/div/input')
last.send_keys(Rue_Adresse)
ast = web1.find_element_by_xpath('//*[@id="home-comparator-base"]/div[2]/div/div[2]/div/form/div[1]/div[1]/div/div[1]/div[2]/div/div[2]/button')
ast.click()
【问题讨论】:
-
为什么不使用更好的 xpath 并使用 clicsk 来“打开”下拉菜单并选择您请求的值
标签: python html selenium selenium-webdriver python-requests