在我可以用VBA打開的頁面內;我想點擊一個表中的第一個鏈接,然後拷貝一些數據,關閉該窗口,點擊表格的第二個鏈接等通過Internet Explorer的VBA,查找文本字符串並使用它
<a title="Open"
onmouseover="javascript:window.status='Click here!';return true;"
onmouseout="javascript:window.status='';return true;"
onclick="OpenWindow(this.href, 'Profile_5193622', 760, 565); return false;"
href="/Pages/Popups/Profile.aspx?pid=5193622">
我想用「/頁/彈出窗口/ Profile.aspx?pid = 5193622「,然後導航到它。我該如何去解決這個問題?
你必須點擊幾個地方纔能到達那裏。這將帶你在那裏:
Sub ExtractFirstLeagueData()
Dim IE As Object, obj As Object
Dim League As Object
Dim links, link
Dim dict As Object
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
IE.navigate ("http://whatifsports.com/hbd/Pages/Main/WorldRedirect.aspx?id=3")
WaitFor IE
IE.navigate ("http://whatifsports.com/HBD/Pages/World/PlayerSearch.aspx")
WaitFor IE
IE.document.getelementsbyname("ctl00$ctl00$ctl00$Main$PageOptionsPlaceHolder$PageOptionsPlaceHolder$lNameTextBox")(0).Value = "a"
IE.document.getelementsbyname("ctl00$ctl00$ctl00$Main$PageOptionsPlaceHolder$PageOptionsPlaceHolder$LevelDropDown$LevelDropDown")(0).Value = "5"
IE.document.forms(0).submit
WaitFor IE
Set dict = CreateObject("scripting.dictionary")
WaitFor IE
'collect the player links
Set links = IE.document.getElementsByTagName("a")
WaitFor IE
For Each link In links
If link.href Like "*/Popups/PlayerProfile.aspx?pid=*" Then
dict.Add link.innertext, link.href
End If
Next link
'navigate to each page and collect info
For Each link In dict.keys
IE.navigate dict(link)
WaitFor IE
Debug.Print IE.document.URL
'get player info here...
Next link
End Sub
Sub WaitFor(IE As Object)
While IE.readyState <> 4
DoEvents
Wend
End Sub
不必加載每個鏈接後會回到談判桌前的,它會更容易收集所有的鏈接在一個數組或集合,然後遍歷它們並從每個目標頁面收集所需的數據。如果您需要更具體的幫助,最好編輯您的問題以包含您當前的代碼。 –