Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
For the extraction of text from a chat window I started off by gathering the window handles.
I managed doing this by the following code:
import time, win32gui
def callback(hwnd, IEServers):
if win32gui.GetClassName(hwnd) == 'Internet Explorer_Server':
IEServers.append(hwnd)
print "IE server found:", hwnd
time.sleep(3)
mainHwnd = win32gui.GetForegroundWindow()
IEServers = []
win32gui.EnumChildWindows(mainHwnd, callback, IEServers)
for serv in IEServers:
print win32gui.GetClassName(serv)
Next thing I want to do is get the content (inner html?) as a string.
I believe it can be done via a IHTMLDocument2 object.
Info: http://support.microsoft.com/kb/q249232
How to do this?
You can try something like this. Maybe not exactly what you want but should get you on your way:
import time, win32gui
import win32com.client
time.sleep(2)
mainHwnd = win32gui.GetForegroundWindow()
s = win32com.client.Dispatch("Shell.Application")
for w in s.Windows():
if int(w.Hwnd) == mainHwnd:
print w.LocationURL
print w.Document.body.innerText
print w.Document.body.innerHTML
break
I think innerText is what you want, but I included several attributes so you can take your pick. This will only work with IE, of course.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.