【问题标题】:I'd like the browser to display data from "2015 to 2015" in white我希望浏览器以白色显示“2015 年至 2015 年”的数据
【发布时间】:2022-01-17 21:26:54
【问题描述】:

'''蟒蛇''' 从硒导入网络驱动程序 从 webdriver_manager.chrome 导入 ChromeDriverManager 从 selenium.webdriver.common.by 导入 从 selenium.webdriver.chrome.service 导入服务 从 selenium.webdriver.common.keys 导入密钥 从 selenium.common.exceptions 导入 NoSuchElementException 从 selenium.common.exceptions 导入

ElementNotInteractableException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
from selenium.webdriver.common.action_chains import ActionChains
import  time

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

driver.get("https://www.pakwheels.com/")
print(driver.title)


year_of_model=driver.find_element(By.ID,"home-query")

year_of_model.send_keys("2015")
search_button=driver.find_element(By.ID,"home-search-btn")
search_button.click()

colour = driver.find_element(By.XPATH, '//*[@id="collapse_16"]/div/ul/li[1]//a/input')
driver.execute_script("arguments[0].click();", colour)
try:
    From_year = driver.find_element(By.ID, "yr_from")
    To_year = driver.find_element(By.ID, "yr_to")
    From_year.send_keys("2015")
    To_year.send_keys("2015")
    go = driver.find_element(By.ID, "yr-go").click()
except ElementNotInteractableException as e:
    print(f"The Error is:{e} ")
time.sleep(30)

我觉得少了点什么

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver web-scraping


    【解决方案1】:
    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager
    from selenium.webdriver.common.by import By
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.common.keys import Keys
    from selenium.common.exceptions import NoSuchElementException
    from selenium.common.exceptions import ElementNotInteractableException
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import Select
    from bs4 import BeautifulSoup
    from selenium.webdriver.common.action_chains import ActionChains
    import  time
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
    
    driver.get("https://www.pakwheels.com/")
    driver.implicitly_wait(10)
    print(driver.title)
    
    #//*[@class="btn btn-sm btn-link-outline btn-classified"]
    # year_of_model=driver.find_element(By.ID,"home-query").send_keys("2015")
    #
    # search_button=driver.find_element(By.ID,"home-search-btn")
    # search_button.click()
    driver.find_element(By.XPATH,'//*[@class="btn btn-sm btn-link-outline btn-classified"]').click()
    
    
    try:
    
    
        From_year = driver.find_element(By.ID, "yr_from")
    
        To_year = driver.find_element(By.ID, "yr_to")
        From_year.send_keys("2015")
        To_year.send_keys("2015")
        Go_ = driver.find_element(By.ID, "yr-go")
        Go_.click()
        time.sleep(3)
    
        colour = driver.find_element(By.XPATH, '//div[@id="collapse_16"]/div/ul/li[1]/label/a/input')
        driver.execute_script("arguments[0].click();", colour)
        time.sleep(5)
    
    
    
    except ElementNotInteractableException as e:
        print(f"The Error is:{e} ")
    
    time.sleep(30)
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2015-11-03
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    相关资源
    最近更新 更多