接下来的两篇我将介绍怎样从DOM流中解析出组成网页的最基本的两种元素:文字和图像。
上一篇我说过网页是由许多嵌套的frame组成,而每一个frame都是一个独立的单元,他们包含自己的文字和图片。解析文字和图片有以下两种情况:
1. 他们都直接放置在网页“BODY”层,此时我不用考虑这些frame导致的布局影响。这是最简单的一种情形。
2. 而常见的情形是他们被放置于嵌套的frame中,比如Button控件上的文字,TextBox控件中的文字等。
l 文字
1. “BODY“层的文字
文字在DOM语言中有好多种标签可以代表他,比如Label,Title,和Anchor等等。他们都表示有文字。
· 首先,我需要得到文字的位置以及他的本体文字,这可一从IHTMLElement接口中获得。
IHTMLElement Members(从MSDN摘录的片段)
offsetParent |
Retrieves a reference to the container object that defines the IHTMLElement::offsetTop and IHTMLElement::offsetLeft properties of the object. |
offsetHeight |
Retrieves the height of the object relative to the layout or coordinate parent, as specified by the IHTMLElement::offsetParent property. |
offsetLeft |
Retrieves the calculated left position of the object relative to the layout or coordinate parent, as specified by the IHTMLElement::offsetParent property. |
offsetParent |
Retrieves a reference to the container object that defines the IHTMLElement::offsetTop and IHTMLElement::offsetLeft properties of the object. |
offsetTop |