使用Python和Pywin从WebBrowser的HTMLElement获取InnerText

时间:2019-03-25 12:17:33

标签: python vba sap win32com pywin

我正在尝试使用Python上的pywin(win32com)库获取已打开的WebBrowser的HTMLElement的InnerText属性。

我有一个WebBrowser,它具有Document属性(对象HTMLDocument),具有一些方法,例如:

getElementsByTagName(string TagName)

https://cdn3.imggmi.com/uploads/2019/3/25/04b5bce44c15b2f06369d010b71d9a70-full.png

当我尝试在Python上使用此方法时,它说:

TypeError: getElementsByTagName() takes 1 positional argument but 2 were given

但是当我尝试在VBA上使用此方法时,它会成功。

Python代码

document = browser_handle.document
elements = document.getElementsByTagName("td")

TypeError: getElementsByTagName() takes 1 positional argument but 2 were given

VBA代码

Set BrowserHandle = session.findById("wnd[0]/usr/tabsSO33_TAB1/tabpTAB1/ssubSUB1:SAPLSO33:1100/cntlCONTROL/shellcont/shell").BrowserHandle
Set Document = BrowserHandle.Document
Set Elements = Document.getElementsByTagName("td")
MsgBox Elements.Item(0).InnerText

0 个答案:

没有答案