Selenium下拉选项无法网页抓取

时间:2018-01-16 09:34:45

标签: python selenium web-scraping

所以我必须从https://auto-buy.geico.com/nb#/sale/vehicle/gskmsi/网上搜集汽车年份,型号和制作的信息(如果链接不起作用,请转到' https://geico.com&#39 ;,填写邮政编码为' 75002',在客户信息中输入随机详细信息,您将登陆车辆信息链接。)

浏览了各种答案后,我发现每次选择菜单中的选项时,由于浏览器发送JavaScript请求,我无法使用机械化或类似的东西。留下像Selenium这样的东西来帮助我。

以下是我的代码:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
from selenium import webdriver


driver = webdriver.Ie("IEDriverServer.exe")
WebDriverWait(driver, 10)
driver.get('https://auto-buy.geico.com/nb#/sale/customerinformation/gskmsi')
html = driver.page_source
soup = BeautifulSoup(html)

select = Select(driver.find_element_by_id('vehicleYear'))
print(select)

输出为空[],因为它无法找到表单。

请让我知道如何从页面的表格中选择数据。

P.S。:虽然我使用过IE浏览器,但欢迎使用Mozilla或Chrome进行任何代码修正。

1 个答案:

答案 0 :(得分:0)

  1. 您需要填写"客户"中的所有信息。使用Selenium选项卡,然后等待此select元素的出现:

    select_element.select_by_visible_text("2017")
    
  2. 然后选择所需的选项:

    {{1}}
  3. 希望它可以帮到你!

相关问题