파이썬 selenium 모듈에서 동적으로 로딩된 html내용 업데이트 방법?

글쓴이: 익명 사용자 / 작성시간: 일, 2017/06/18 - 5:17오전
파이썬으로 selenium 모듈을 이용해 네이버 글 자동수정하는 스크립트를 만들려고 하는데 카페의 동적 작용에서 막히네요?
게시글이 있는 부분이 iframe이고 동적으로 마지막으로 로딩되는데 selenium은 동적으로 로딩되는 부분을 못잡아내네요ㅠㅠ 방법이 없을까요.
스크립트는 다음과 같습니다.
import os from selenium import webdriver chromePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'chromedriver') # setting up browser. this is Chrome-based. driver = webdriver.Chrome(chromePath) # address. testing purpose. driver.get('http://cafe.naver.com/twcenter/22498') driver.implicitly_wait(15) # tried waiting if dynamic script gets loaded. it didn't. # opening the frame. iframe = driver.find_element_by_id('cafe_main') print(iframe) driver.switch_to.frame(iframe) # an xpath going to a button opening forum post lists. xpath = ".//*[@id='main-area']/div[3]/div/div[2]/p/a" try: # not working at the moment as iframe is not being dynamically updated in selenium. driver.find_element_by_xpath(xpath).click() except Exception as e: print(e)
우선 저거 외에 아래 방법도 써봤는데 효과는 없었습니다.
iframe = driver.find_element_by_id('cafe_main') driver.switch_to.frame(iframe)
try: element = WebDriverWait(driver, 20).until( expected_conditions.presence_of_element_located((By.XPATH, ".//*[@id='modifyFormBtn']/p/a")) ) finally: print(driver.page_source)
Forums:
댓글 달기