2009-11-02 71 views
1

我使用win32com.client來控制Python中的IE實例。如何點擊某個頁面上的鏈接(例如,使用導航鏈接href是不可接受的,因爲它不會觸發引用者發送)?這是基礎:如何點擊win32com.client IE中的鏈接?

import random 
import time 
from win32com.client import Dispatch 

ie = Dispatch("InternetExplorer.Application") 
ie.visible = 1 

ie.navigate('http://digg.com') 

while (ie.ReadyState != 4): 
    time.sleep(0.05) 

hrefs = ie.document.getElementsByTagName("A") 
href = hrefs[random.randrange(hrefs.length)] 
#How to click this one? 

回答

1

您是否嘗試過使用navigate方法的Headers參數手動設置引薦頭這個「引薦:http://digg.com」。

+0

很好,如果說鏈路出現什麼不該它的href由於一些JS功能?在這種情況下,瀏覽器將導航到它不會訪問的頁面,如果有用戶 – Fluffy 2009-11-02 15:43:33

+0

以我建議的方式欺騙​​好點只會在有限的情況下工作。 – 2009-11-02 16:37:20