2015-06-04 45 views
0

在我可以用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 
+1

不必加載每個鏈接後會回到談判桌前的,它會更容易收集所有的鏈接在一個數組或集合,然後遍歷它們並從每個目標頁面收集所需的數據。如果您需要更具體的幫助,最好編輯您的問題以包含您當前的代碼。 –

回答

0
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 
+0

這需要多長時間才能運行?似乎我的宏被卡住尋找鏈接。 –

+0

當我跑它很快 –

+0

我更新了我的帖子,包括你的添加。我的宏沒有執行「對於鏈接中的每個鏈接」部分。我做錯了什麼? –

相關問題