2016-12-05 24 views
0

私はPythonSeleniumFirefoxを使用してコンテンツを取得しています。ScrapyとSeleniumを使用したPython JavaScriptを取得する

<html> 
 
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"> 
 

 
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" onResize="resize();" bgcolor="#ffffff"> 
 
    <iframe id="iframe" align="center" width="100%" height="100%" frameborder="0" marginWidth="0" marginHeight="0" src="" style="margin-top:1px;margin-left:1px;"></iframe> 
 
</body> 
 
<script> 
 
    var eventTime = new Date(); 
 

 
    function activeEvent() { 
 
     eventTime = new Date(); 
 
    } 
 

 
    var height = 0; 
 
    var width = 0; 
 
    resize(); 
 

 
    function setTitle(message) { 
 
     document.title = message; 
 
    } 
 

 
    function resize() { 
 
     height = document.body.clientHeight - 2; 
 
     width = document.body.clientWidth - 2; 
 
     if (height < 480) height = 480; 
 
     if (width < 640) width = 640; 
 
     document.getElementById("iframe").height = height; 
 
     document.getElementById("iframe").width = width; 
 
    } 
 
    setInterval("resize()", 1000); 
 
    document.getElementById("iframe").src = "http://xxxxxx.com:80/lhscm/framework/mainform/navui/nav3mainform.do?height=" + height + "&width=" + width; 
 
</script> 
 

 
</html>

をしかしsrcリンクを取得することはできませんセレンdriver.page_sourceを使用してHTMLを生成:ウェブサイトHTMLは以下の通りです。
コンテンツを取得するにはどうすればよいですか?

+0

私はfirefox firebugを使用して、私はhtml要素を取得できます! –

答えて

0

あなたのページの本文は、iframeの中に完全に位置しているようですので、取得するにはこのフレームに切り替える必要があります。以下を試してください:

driver.switch_to_frame('iframe') 
source = driver.page_source 
driver.switch_to_default_content() 
+0

親愛なるAndersson、はい、あなたは答えが働いて、ありがとう!!! –

+0

親愛なるAnderssonさん、親愛なる質問があります.JSでHTMLが生成され、複数のiframeがあり、すべてのフレームにID、名前がありません –

+0

'iframe'と' XPath'を 'driver.find_element_by_xpath( '// iframe [@ class =" some_class_name "]')のように' driver.switch_to_frame 'とマッチさせることができます。 )) ' – Andersson

関連する問題