Microsoft HTML Object Library - VB
Формулировка задачи:
Подскажите каким образом можно получить контент на странице в виде таблиц, текса и т.д. ( т.е. такие объекты как HTMLTable )
Решение задачи: «Microsoft HTML Object Library»
textual
Листинг программы
<font color="blue">Private</font> <font color="blue">Sub</font> Form_Load() <font color="blue">Call</font> wb.Navigate(<font color="teal">"www.google.com"</font>) <font color="blue">End</font> <font color="blue">Sub</font> <font color="blue">Private</font> <font color="blue">Sub</font> wb_DocumentComplete(<font color="blue">ByVal</font> pDisp <font color="blue">As</font> <font color="blue">Object</font>, URL <font color="blue">As</font> Variant) <font color="blue">If</font> (pDisp <font color="blue">Is</font> wb.<font color="blue">object</font>) <font color="blue">Then</font> <font color="blue">Call</font> LoadPageIntoTree <font color="blue">End</font> <font color="blue">Sub</font> <font color="blue">Private</font> <font color="blue">Sub</font> LoadPageIntoTree() <font color="blue">Dim</font> i <font color="blue">As</font> <font color="blue">Integer</font> <font color="blue">Dim</font> nodeObj <font color="blue">As</font> Node tvwView.Nodes.Clear <font color="blue">For</font> i = <font color="darkblue"><b>0</b></font> <font color="blue">To</font> wb.Document.All.length - <font color="darkblue"><b>1</b></font> <font color="blue">If</font> wb.Document.All(i).tagName = <font color="teal">"HTML"</font> <font color="blue">Then</font> <font color="blue">Exit</font> <font color="blue">For</font> <font color="blue">Else</font> <font color="blue">Set</font> nodeObj = tvwView.Nodes.Add(, , _ <font color="teal">"k"</font> & wb.Document.All(i).sourceIndex, _ wb.Document.All(i).tagName, _ IIf(wb.Document.All(i).children.length = <font color="darkblue"><b>0</b></font>, <font color="darkblue"><b>3</b></font>, <font color="darkblue"><b>2</b></font>)) nodeObj.ExpandedImage = <font color="darkblue"><b>1</b></font> <font color="blue">End</font> <font color="blue">If</font> <font color="blue">Next</font> <font color="blue">If</font> i = wb.Document.All.length - <font color="darkblue"><b>1</b></font> <font color="blue">Then</font> <font color="blue">Exit</font> <font color="blue">Sub</font> <font color="blue">Call</font> ParseAndDisplay(wb.Document.All(i)) <font color="blue">Set</font> nodeObj = <font color="blue">Nothing</font> <font color="blue">End</font> <font color="blue">Sub</font> <font color="blue">Private</font> <font color="blue">Sub</font> ParseAndDisplay(htmlObj <font color="blue">As</font> HTMLHtmlElement) <font color="blue">On</font> <font color="blue">Error</font> <font color="blue">Resume</font> <font color="blue">Next</font> <font color="blue">Dim</font> nodeObj <font color="blue">As</font> Node <font color="blue">Dim</font> childObj <font color="blue">As</font> HTMLHtmlElement <font color="blue">With</font> tvwView <font color="blue">If</font> htmlObj.parentElement <font color="blue">Is</font> <font color="blue">Nothing</font> <font color="blue">Then</font> <font color="blue">Set</font> nodeObj = .Nodes.Add(, , <font color="teal">"k"</font> & htmlObj.sourceIndex, htmlObj.tagName, <font color="darkblue"><b>2</b></font>) nodeObj.ExpandedImage = <font color="darkblue"><b>1</b></font> <font color="blue">Else</font> <font color="blue">Set</font> nodeObj = .Nodes.Add(<font color="teal">"k"</font> & htmlObj.parentElement.sourceIndex, tvwChild, _ <font color="teal">"k"</font> & htmlObj.sourceIndex, htmlObj.tagName, _ IIf(htmlObj.children.length = <font color="darkblue"><b>0</b></font>, <font color="darkblue"><b>3</b></font>, <font color="darkblue"><b>2</b></font>)) nodeObj.ExpandedImage = <font color="darkblue"><b>1</b></font> <font color="blue">End</font> <font color="blue">If</font> <font color="blue">If</font> htmlObj.children.length = <font color="darkblue"><b>0</b></font> <font color="blue">Then</font> <font color="blue">Exit</font> <font color="blue">Sub</font> <font color="00AA00">'no children, exit sub</font> <font color="blue">For</font> <font color="blue">Each</font> childObj <font color="blue">In</font> htmlObj.children <font color="blue">Call</font> ParseAndDisplay(childObj) <font color="blue">Next</font> <font color="blue">End</font> <font color="blue">With</font> <font color="blue">Set</font> nodeObj = <font color="blue">Nothing</font> <font color="blue">Set</font> childObj = <font color="blue">Nothing</font> <font color="blue">End</font> <font color="blue">Sub</font>
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д