我有一个有多种形式的网页。每个提交的表单都会打开一个新页面我正在尝试从这些页面获取数据。使用下面的代码,我可以打开页面,但数据是从表单页面提取的,而不是提交后出现的页面。
我看了这个解决方案,但在我的情况下它不起作用。
excel vba form submit and parse data from result
这是我的代码;
Set formsw = IE.document.forms
For Each form In formsw
For Each elem In form.elements
If elem.Value = "Show Summary (Html)" Then elem.Click
Do Until IE.ReadyState = 4: DoEvents: Loop
Do While IE.Busy: DoEvents: Loop
Sheet1.Activate
Sheet1.Cells.ClearContents
r = 0
For Each TRelement In IE.document.getElementsByTagName("TR")
Sheet1.Range("A1").Offset(r, 0).Value = TRelement.innerText
r = r + 1
Next
End If
Next
Next
Set form = Nothing
以下是来源的一部分;
<input class="newInputButton" type="button" name="btnSubmit" width="100%" value="Show Summary (Html)" onclick="javascript:form1.action='/BEP/ShowApproved?w=0'; form1.target='_blank'; form1.submit();">
<input class="newInputButton" type="button" name="btnSubmit" width="100%" value=""Show Details (Html)" onclick="javascript: form1.action='/BEP/ShowApproved?w=0'; form1.target='_blank'; form1.submit();">
<input class="newInputButton" type="button" name="btnSubmit" width="100%" value="Show Summary (Html)" onclick="javascript:form2.action='/BEP/ShowApproved?w=0'; form2.target='_blank'; form2.submit();">
<input class="newInputButton" type="button" name="btnSubmit" width="100%" value=""Show Details (Html)" onclick="javascript: form2.action='/BEP/ShowApproved?w=0'; form2.target='_blank'; form2.submit();">
感谢任何帮助,谢谢!
答案 0 :(得分:1)
听起来您需要将IE重点放在新网页上。以下代码计算IE的所有打开实例并检索其URL和标题。如果新网页的网址或标题中有一些特征词,那么您可以在下面使用它们来获取宏来控制新网页。此示例使用页面标题,但您也可以使用该URL。
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
my_title = objShell.Windows(x).Document.Title
If my_title Like "Some characteristic words from your new web page" Then 'find the new web page
Set ie = objShell.Windows(x)
Exit For
Else
End If
Next