Selenium 填写表单信息python [英] Selenium filling form information python
问题描述
我正在尝试从以下网站抓取:https://www.legifrance.gouv.fr/rechJuriJudi.do?reprise=true&page=1
I am trying to scrape from the following website: https://www.legifrance.gouv.fr/rechJuriJudi.do?reprise=true&page=1
我只对它可以呈现的特定结果子集感兴趣,所以我想使用 Selenium 来填写搜索查询.
I am only interested in a specific subset of the results it can present so I want to use Selenium to fill in a search query.
更具体地说,我感兴趣的有两个部分:
To be more specific there are 2 parts I am interest in:
<select name="champJuridictions" id="champ1" class="textarea"><option value="" class="optionPaire">-- Toutes les juridictions --</option>
<option value="cour de cassation" selected="selected" class="optionImpaire">Cour de cassation</option>
<option value="juridiction d'appel" class="optionPaire">Juridictions d'appel</option>
<option value="juridictions du premier degre" class="optionImpaire">Juridictions du premier degré</option>
<option value="tribunal des conflits" class="optionPaire">Tribunal des conflits</option></select>
这是一个下拉窗口,我想在其中选择一个选项(第一个).
Which is a dropdown window, where I want to pick one of the options (the first one).
另一个是一个开放的领域,我必须用一个词来填充.
The other is an open field which I have to fill with a word.
<span class="inputCode">
<input type="text" name="champMotsRecherches1" value="" id="champ7" class="textarea">
</span>
其中 value 应等于Impôt".
Where value should be equal to "Impôt".
我将如何填写这样的查询?
How would I fill such a query ?
推荐答案
对于文本框,可以使用 Selenium find_element_by_id
方法,然后在上使用 send_keys
方法该元素可以发送您想要的任何输入.
For a text box, you can use the Selenium find_element_by_id
method and then use the send_keys
method on that element to send whatever input you wish.
browser.find_element_by_id("my_id").send_keys("my_text")
对于下拉菜单,您可以使用 select_by_index
或 select_by_visible_text
.
For a dropdown menu, you can use either select_by_index
or select_by_visible_text
.
menu = browser.find_element_by_id("my_dropdown_menu")
menu.select_by_index(index)
menu.select_by_visible_text("text")
其他资源:
http://selenium-python.readthedocs.io/locating-elements.html
http://thiagomarzagao.com/2013/11/12/webscraping-with-selenium-part-1/
这篇关于Selenium 填写表单信息python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!