1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How do I know where and what to place inside these highlighted parentheses?

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to scrape a website with Selenium and Python. At the bottom of the code, am I supposed to customize all of the selectors, depending on my target website? Or do I leave it as it for the code no matter the site of choice?


    from bs4 import BeautifulSoup
    import time
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.wait import WebDriverWait

    time.sleep(3)

    # Set some Selenium Options
    options = webdriver.ChromeOptions()
    # options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')

    # Webdriver
    wd = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=options)
    # URL
    url = 'https://www.techpilot.de/zulieferer-suchen?laserschneiden%202d%20(laserstrahlschneiden)'

    # Load URL
    wd.get(url)

    # Get HTML
    soup = BeautifulSoup(wd.page_source, 'html.parser')

    wait = WebDriverWait(wd, 15)
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#bodyJSP #CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll"))).click()
    wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "#efficientSearchIframe")))
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".hideFunctionalScrollbar #CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll"))).click()
    #wd.switch_to.default_content() # you do not need to switch to default content because iframe is closed already
    wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".fancyCompLabel")))

    Continue reading...

Compartilhe esta Página