Код: Выделить всё
from selenium.common.exceptions import StaleElementReferenceException
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://esco.ec.europa.eu/en/classification/skill_main")
driver.implicitly_wait(10)
wait = WebDriverWait(driver, 20)
# Define a function to click all expandable "+" buttons
def click_expand_buttons():
while True:
try:
# Find all expandable "+" buttons
expand_buttons = wait.until(EC.presence_of_all_elements_located(
(By.CSS_SELECTOR, ".api_hierarchy.has-child-link"))
)
# If no expandable buttons are found, we are done
if not expand_buttons:
break
# Click each expandable "+" button
for button in expand_buttons:
try:
driver.implicitly_wait(10)
driver.execute_script("arguments[0].click();", button)
# Wait for the dynamic content to load
time.sleep(1)
except StaleElementReferenceException:
# If the element is stale, we find the elements again
break
except StaleElementReferenceException:
continue
# Call the function to start clicking "+" buttons
click_expand_buttons()
html_source = driver.page_source
# Save the HTML to a file
with open("/Users/federiconutarelli/Desktop/escodata/expanded_esco_skills_page.html", "w", encoding="utf-8") as file:
file.write(html_source)
# Close the browser
driver.quit()
Код: Выделить всё
[url=#overlayspin]S - skills[/url]
Подробнее здесь: https://stackoverflow.com/questions/781 ... c-category