Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用python填写web表单_Python_Html_Selenium_Selenium Webdriver_Python Requests - Fatal编程技术网

如何用python填写web表单

如何用python填写web表单,python,html,selenium,selenium-webdriver,python-requests,Python,Html,Selenium,Selenium Webdriver,Python Requests,我试图通过python脚本填写此表单: 但不幸的是,我找不到允许我从下拉列表中选择值的代码 您可以注意到,在html中,我们没有下拉列表中的不同选项 你能告诉我如何制作一个python脚本,让我填写这个表单吗 先谢谢你 下面的代码显示了我迄今为止所做的工作,但它不允许我从下拉列表中选择一个值 from selenium import webdriver import time from selenium.webdriver.support.ui import WebDriverWait fro

我试图通过python脚本填写此表单:

但不幸的是,我找不到允许我从下拉列表中选择值的代码

您可以注意到,在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来突出显示所有不同的输入值。右键单击要输入信息的元素,单击inspect,然后右键单击该元素并单击“Copy Xpath”。从那里我将使用Pyautogui,这将允许您接管键盘。然后,您可以使用pyautogui.hotkey(“向下”)向下滚动到所需的选择。您还可以使用pyautogui.write('text here')填充不同的文本框。Pyautogui与selenium配合得很好,您可以使用selenium激活您想要使用的区域,并使用Pyautogui对其进行操作。

为什么不使用更好的XPath和clicsk来“打开”下拉列表并选择所需的值谢谢您的回答,但我无法选择我需要的内容。事实上,pyautogui在使用Selenium打开的激活区域中不起作用。它在我的jupyter页面上工作,而不是我需要它工作的地方。你有什么建议吗?谢谢