在一个页面内,我能够用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">
我想用URL中的 "PagesPopupsProfile.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
Dim links, link
Dim dict As Object
'-------------------------
'get to the right page...
'-------------------------
Set dict = CreateObject("scripting.dictionary")
'collect the player links
Set links = IE.document.getElementsByTagName("a")
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
助手子。
Sub WaitFor(IE As Object)
While IE.readyState <> 4
DoEvents
Wend
End Sub