2012-02-09 40 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

嘗試硒http://seleniumhq.org/ – nosklo 2012-02-09 17:54:51

回答

0

也許試着通過它的id訪問元素iframe。

東西長, 網頁/文件的線你已經裝載在它下面的元素,

<iframe id='myframe'>

從您的代碼嘗試這樣的事情, doc.myframe.Login.user

你可以做的一件事是打開python的REPL,並使用你的doc對象來弄清楚如何訪問你要找的元素。