2017-12-18 17 views
5

저는 웹 페이지의 일부 항목을 구문 분석하기 위해 Python과 함께 셀렌과 스크립트를 작성했습니다. 나는 어쨌든 그것을 작동시킬 수 없다. 이후 아이템은 iframe 내에 (아마도) 있습니다. 나는 그것을 바꾸려고했지만 어떤 효과도 없다. 나는 TimeoutException을 제외하고는 여전히 아무것도 얻지 못하고 있는데, 내가 iframe으로 전환하려고 시도한 라인을 때린다. 어떻게 작동시킬 수 있습니까? 미리 감사드립니다 : 여기에웹 페이지에서 일부 항목을 가져 오는 데 문제가 발생했습니다.

는 웹 페이지의 링크를 간다 : URL

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 

url = "replace_with_above_url" 

driver = webdriver.Chrome() 
driver.get(url) 
wait = WebDriverWait(driver, 10) 

wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623"))) 

for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".quick .apply-common-tooltip"))): 
    print(item.text) 

driver.quit() 

요소를하는 내에서 항목 난 후 해요 :

<div class="quick"> 
    <span class="apply-common-tooltip">5</span> 
    <span class="apply-common-tooltip">1h</span> 
    <span class="apply-common-tooltip selected">1D</span> 
    <span class="apply-common-tooltip">1M</span> 
    <span class="apply-common-tooltip">1D</span> 
</div> 

이 내가 가진 기대하고있어 출력 (이다 그것은 CSS 선택자를 사용하여 그들을 얻으려고 할 때 로컬로 작동합니다.) :

5 
1h 
1D 
1M 
1D 

This 이 웹에 모습입니다 :

enter image description here

답변

4

필요한 노드는 2 개 중첩 된 iframe을 내부에있는, 그래서 당신은 하나 그들을 하나로 전환 할 필요가있다. 두 번째 것의 id/name은 동적으로 생성됩니다. 그냥 그냥 불가능 선생님 앤더슨 있습니다

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, ".abs"))) 
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id^='tradingview_']"))) 
+0

wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623"))) 

를 교체하려고합니다. 그래, 너는 그것을 만들었다. – SIM