views:

246

answers:

2

Hello, I'm using win32com.client to control an IE instance in Python. How can I click a link on a certain page (e.g. using navigate to link href isn't acceptable since it won't trigger referer sending)? Here is the base:

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  A: 

Have you tried using the Headers parameter of the navigate method to manually set the Referrer header to this "Referer: http://digg.com".

Tendayi Mawushe
well, what if, say the link goes not to it's href thanks to some JS function? in this case the browser would navigate to a page it wouldn't visit if there was a user
roddik
Good point cheating in the manner I suggested would only work in limited circumstances.
Tendayi Mawushe
A: 

Turns out it has .click() method. Where is Captain Obvious when I need him?!

http://msdn.microsoft.com/en-us/library/ms535173%28VS.85%29.aspx

roddik