单击selenium中的按钮

2024-10-02 18:22:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我想训练selenium并在网站上抓取一些信息:https://www.stepstone.at/?gclid=CjwKCAiApNSABhAlEiwANuR9YAJKRjy_7hDuKPpJRL-zfaqDqc2zlAo9EgGmRHgs1Bvx5WRu_3ZPkBoC9_cQAvD_BwE&&ef_id=CjwKCAiApNSABhAlEiwANuR9YAJKRjy_7hDuKPpJRL-zfaqDqc2zlAo9EgGmRHgs1Bvx5WRu_3ZPkBoC9_cQAvD_BwE:G:s&cid=SEAdvert_Google_SEARCH_AT_Gen-E_c_Jobs_jobs_FPd_EtaId4-L1&loc_interest=&loc_physical=1000852&s_kwcid=AL!524!3!494891721515!e!!g!!jobs

这是我的代码:

search_job = input("Write your job that you are searching for: ")
search_city = input("Write your city where you want to find your job: ")
search_working_times = input("Write your working times: ")
PATH = "C:\Program Files\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.stepstone.at/?gclid=CjwKCAiApNSABhAlEiwANuR9YAJKRjy_7hDuKPpJRL-zfaqDqc2zlAo9EgGmRHgs1Bvx5WRu_3ZPkBoC9_cQAvD_BwE&&ef_id=CjwKCAiApNSABhAlEiwANuR9YAJKRjy_7hDuKPpJRL-zfaqDqc2zlAo9EgGmRHgs1Bvx5WRu_3ZPkBoC9_cQAvD_BwE:G:s&cid=SEAdvert_Google_SEARCH_AT_Gen-E_c_Jobs_jobs_FPd_EtaId4-L1&loc_interest=&loc_physical=1000852&s_kwcid=AL!524!3!494891721515!e!!g!!jobs")
driver.implicitly_wait(5)

your_competence = driver.find_element_by_name("ke")
your_competence.send_keys(search_job)

your_city = driver.find_element_by_name("ws")
your_city.send_keys(search_city)

if "Vollzeit" == search_working_times:
    vollzeit = driver.find_element_by_id("ch1").click()

当我运行此代码时,除了单击按钮之外,其他任何操作都可以 控制台显示以下错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input class="quickfilters__list-item-checkbox" type="checkbox" name="wt" value="80001" id="ch1"> is not clickable at point (21, 307). Other element would receive the click: <section class="prompt-container">...</section>
  (Session info: chrome=88.0.4324.104)

有人能帮我吗:)


Tags: idcityinputsearchyourdriverjobsjob
1条回答
网友
1楼 · 发布于 2024-10-02 18:22:57

我复制了你的代码,看起来这是因为出现了一个带有术语和规则的弹出窗口。在尝试使用页面之前,只需在代码中添加driver.find_element_by_id("ccmgt_explicit_accept").click()。有了这样的代码,一切都很好:

    search_job = input("Write your job that you are searching for: ")
    search_city = input("Write your city where you want to find your job: ")
    search_working_times = input("Write your working times: ")
    driver = webdriver.Chrome(ChromeDriverManager().install())
    driver.get(
        "https://www.stepstone.at/?gclid=CjwKCAiApNSABhAlEiwANuR9YAJKRjy_7hDuKPpJRL-zfaqDqc2zlAo9EgGmRHgs1Bvx5WRu_3ZPkBoC9_cQAvD_BwE&&ef_id=CjwKCAiApNSABhAlEiwANuR9YAJKRjy_7hDuKPpJRL-zfaqDqc2zlAo9EgGmRHgs1Bvx5WRu_3ZPkBoC9_cQAvD_BwE:G:s&cid=SEAdvert_Google_SEARCH_AT_Gen-E_c_Jobs_jobs_FPd_EtaId4-L1&loc_interest=&loc_physical=1000852&s_kwcid=AL!524!3!494891721515!e!!g!!jobs")
    driver.implicitly_wait(5)

    driver.find_element_by_id("ccmgt_explicit_accept").click()

    your_competence = driver.find_element_by_name("ke")
    your_competence.send_keys(search_job)

    your_city = driver.find_element_by_name("ws")
    your_city.send_keys(search_city)

    if "Vollzeit" == search_working_times:
        vollzeit = driver.find_element_by_id("ch1").click()

相关问题 更多 >