2017-05-04 8 views
2

セレンを使ってウェブページを掻き取ろうとしています。ページを調べて右クリックすることによって提案されたxpathsは不安定な種類(/ html/body/table [2]/tbody/tr [1]/td/form/table/tbody/tr [2])です。だから私は、代わりに次の解決策を試してみました:スクリプトを実行しているページでxpathを見つける

driver = webdriver.Chrome("path") 
driver.get("https://www.bundesfinanzhof.de/entscheidungen/entscheidungen-online") 
time.sleep(1) 
links=driver.find_element_by_xpath('//tr[@class="SuchForm"]') 

あるいは

links=driver.find_elements_by_xpath('//*[@class="SuchForm"]') 

結果を返しませんが。しかし、以前のページに私が入手できます。

<script language="JavaScript" src="/rechtsprechung/jscript/list.js" type="text/javascript"></script> 

私はもはや要素のいずれかを取得することはできません。

links=driver.find_element_by_xpath('//iframe') 
links.get_attribute('src') 

後と思われます。 How do I determine the correct XPath? は、スクリプト内の部分は解析できないことを示しています。しかし、私の後ろの道は私の道の中にいないようです。スクリプトがページ上でどのように動作するのか誤解していますか?

/html/body/table[2]/tbody/tr[1]/td/script 

が、私はこのような問題を作成することを期待する:

は例えば、後にパスが存在します。私は決してプログラマーではないので、この件に関する私の理解は限られています。誰かが問題の内容を説明し、解決策があればそれを説明することはできますか? tableはあなたが必要なtrを取り扱う前に、そのiframeに切り替える必要がありので、iframeの内側に位置しています

Find element text using xpath in selenium-python NOt Working

xpath does not work with this site, pls verify

答えて

1

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

driver.get("https://www.bundesfinanzhof.de/entscheidungen/entscheidungen-online") 
wait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@src='https://juris.bundesfinanzhof.de/cgi-bin/rechtsprechung/list.py?Gericht=bfh&Art=en']"))) 
link = driver.find_element_by_xpath('//tr[@class="SuchForm"]') 

からソリューションを使用しようとしました

お問い合わせe driver.switch_to.default_content()からスイッチバックiframe

関連する問題