2012-02-09 19 views
1

このpythonスクリプトを使用して自動的にサイトにログインしようとしています。Pythonでiframeの内部にフォームを埋め込む方法

from win32com.client import Dispatch 
import win32com.client 
import time,ids 

IE=Dispatch("InternetExplorer.Application") 
IE.Visible=1 
IE.Navigate("Source.html") 
while IE.ReadyState != 4: # Wait for browser to finish loading. 
    time.sleep(1) 
doc = IE.Document # Get the document. 
while doc.readyState != "complete": # Wait for document to finish 
    time.sleep(1) 
doc.Login.USER.value = ids.username  
doc.Login.PASSWORD.value = ids.password 
doc.Login.submit() 
while IE.ReadyState != 4: # Wait for browser to finish loading. 
    time.sleep(1) 
doc = IE.Document # Get the document. 
while doc.readyState != "complete": # Wait for document to finish 
    time.sleep(1) 
time.sleep(30) 
IE.Application.Quit(); 

通常のサイトで正常に動作しますが、Source.htmlはIframeにサイトを読み込みます。 したがって、ユーザー名とパスワードのフィールドはIframe内にあり、データの入力方法はわかりません。

+0

tryセレンhttp://seleniumhq.org/ – nosklo

答えて

0

おそらく、id、要素を使ってiframeにアクセスしてみてください。

ページ/ docにあなたの負荷があなたのコードから

<iframe id='myframe'>

、その中に次の要素を持っている 、の行の長は、この、 doc.myframe.Login.userような何かを試してみてください何か

あなたができることの1つは、Python REPLを開いて、あなたの探している要素にアクセスする方法を理解するためにdocオブジェクトで遊ぶことです。

関連する問題