Selenium을 사용하여 Amazon 검색 결과를 효율적으로 탐색하고 StaleElementException을 방지하려면 어떻게 해야 합니까?
Selenium으로 Amazon 결과 탐색
Selenium을 사용하여 Amazon에서 검색 결과를 반복할 때 발생할 수 있는 일반적인 오류는 StaleElementException입니다. 이 오류는 페이지 변경이나 새로 고침으로 인해 상호작용 중인 요소가 더 이상 DOM에 연결되지 않음을 나타냅니다.
이 문제를 극복하려면 복잡한 논리에 의존하여 특정 요소로 스크롤하는 대신 더 간단한 접근 방식을 취할 수 있습니다. 사용 가능한 "다음" 버튼을 반복적으로 클릭하면 스크립트가 오류 없이 결과 페이지를 이동할 수 있습니다.
이 수정된 코드는 명시적 대기를 활용하여 버튼을 클릭하기 전에 버튼을 클릭할 수 있는지 확인합니다.
from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait as wait from selenium.common.exceptions import TimeoutException driver = webdriver.Chrome() driver.get('https://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=sonicare+toothbrush') while True: try: wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a > span#pagnNextString'))).click() except TimeoutException: break
implicitly_wait() 메서드는 명시적 대기 메서드와 마찬가지로 전체 대기 시간을 보장하지 않는다는 점에 유의하는 것이 중요합니다. 대신 요소가 DOM에 나타날 때까지 드라이버가 기다리는 최대 시간을 나타내며 요소가 감지되면 대기가 갑자기 종료됩니다.
위 내용은 Selenium을 사용하여 Amazon 검색 결과를 효율적으로 탐색하고 StaleElementException을 방지하려면 어떻게 해야 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기