社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python-使用相关下拉列表删除表

ChiaraMZM • 4 年前 • 1854 次点击  

我正在努力获得秘鲁2016年选举的选举结果,按地区分列。正如你在这个链接中看到的( https://www.web.onpe.gob.pe/modElecciones/elecciones/elecciones2016/PRPCP2016/Resultados-Ubigeo-Presidencial.html#posicion ),在选择“范围”时,会出现三个框,标题分别为“部门”、“省”和“区”。我想从“地区”级别的图像表中提取所有结果,并将它们保存在一个表中,但要实现这一点,我必须首先选择“部门”、“省”和“地区” 1

到目前为止,我已经编写了这段代码,将我确定的选项插入下拉列表,但我想知道是否可以自动选择选项。共有1874个区,因此无法手动执行。

我希望你能帮助我。谢谢

import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time

driver = webdriver.Chrome()
driver.get('https://www.web.onpe.gob.pe/modElecciones/elecciones/elecciones2016/PRPCP2016/Resultados-Ubigeo-Presidencial.html#posicion')
time.sleep(4)

selectAmbit = Select(driver.find_element_by_id("cdgoAmbito"))
selectAmbit.select_by_value('P')

time.sleep(2)

selectRegion = Select(driver.find_element_by_id("cdgoDep"))
selectRegion.select_by_value('010000')

time.sleep(2)

selectProvin = Select(driver.find_element_by_id("cdgoProv"))
selectProvin.select_by_value('010200')

time.sleep(2)

selectDistr = Select(driver.find_element_by_id("cdgoDist"))
selectDistr.select_by_value('010202')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/128270
文章 [ 1 ]  |  最新文章 4 年前