2017-03-11 7 views
1

私はsrc="http://example1.com"リンクPythonのセレン、アクセスのdivクラス、IFRAMEのスタイル

<div class="video"> 
    <iframe style="border: none;" src="http://example1.com" width="100%" height="460" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe> 
</div> 
<div style="background-color: #428bca; color: #fff; margin-top: 20px; text-align: left; font-size: 14px;padding: 8px;">Description 
    <a style="color:yellow; font-weight: bold" href="http://example.com">Text</a> 
</div> 

は私が

elems = driver.find_elements_by_xpath("//div[@class='video']") 
for elem in elems: 
    print elem.get_attribute("src") 

かにしようとしたことを取得する必要があります:

element = driver.find_element_by_class_name('video').get_attribute('src') 
print element 

そして他の多くが、そうです何も動作していない、または私は "なし"を見つける アイデア?

答えて

1

src="http://example1.com"class='video'<div>ではありませんが、その子要素で

iframe = driver.find_element_by_css_selector('.video > iframe') 
print iframe.get_attribute('src') 
0

あなたのxpathに追加してみてくださいする必要がありますので、あなたが取得したいことはiframeタグである

element = driver.find_elements_by_xpath("//div[@class='video']/iframe").get_attribute('src') 
print element 
関連する問題