0
我正在使用VBA填充URL中的表單並提交以獲取結果。 當我使用正確的值提交表單並通過VBA提交時,我在另一個URL中獲得結果,但在同一窗口中。VBA在另一個網址但在同一窗口中獲取結果
問題是,我不知道如何改變html引用來開始使用這個新的url來報廢數據。
這裏是我的代碼:
'to refer to the running copy of Internet Explorer
Dim IE As InternetExplorer
'to refer to the HTML document returned
Dim html As HTMLDocument
'open Internet Explorer in memory, and go to website
Set IE = New InternetExplorer
IE.Visible = False
IE.navigate "http://url..."
'Wait until IE is done loading page
Do While IE.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Connecting with http://url..."
DoEvents
Loop
'show text of HTML document returned
Set html = IE.document
'close down IE and reset status bar
Set IE = Nothing
Application.StatusBar = ""
Set txtArea = html.getElementsByTagName("textarea")(0)
txtArea.Value = txtArea_data
Set formSubmit = html.getElementsByName("submit")(1)
formSubmit.Click
'-------------Get results
'Dim html_results As HTMLDocument
IE.navigate "http://new_url" 'Im not sure if I must do it this way...
'Wait until IE is done loading page
Do While IE.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Connecting with http://new_url..."
DoEvents
Loop
Set html = IE.document
Dim trResults As IHTMLElementCollection
Set trResults = html.getElementsByClassName("tr")
MsgBox (trResults.Length) 'At this point, trResults always have 0 results...
你有什麼想法幫助我嗎?
謝謝!
至少,當您設置IE = Nothing時,您無法在後續命令中繼續使用InternetExplorer對象。此外,提交表單應該帶您到另一個網頁,但您不要等待它加載,然後再嘗試''.Navigate'到一個新的URL。我強烈懷疑表單提交是不正確的,但這是猜測而沒有看到頁面的來源。 – Jeeped 2014-10-10 12:01:18