VB obtains all elements of a webpage.

Source: Internet
Author: User
VB obtains all elements of a webpage at a.m. on February 11 ,.
VB obtains all elements of a webpage.

It is as simple as getting all the elements of a webpage:

Dim thehtml as new htmldocument

Set thehtml = wb.doc ument
'Wb = ActiveX webbrowser

'Thehtml. All is it!

...... So it's easy to get all the links! :
Dim colllink as ihtmlelementcollection

'Get all links
Set colllink = thehtml. All. Tags ("")
For I = 0 to colllink. Length-1
Debug. Print "Link" & CSTR (I + 1) & ":" & colllink (I) & vbnewline
Next

I believe that all HTML elements will be conquered in the future!

 

Http://hi.baidu.com/ok100fen/blog/item/34cdea1d2f27fc8c87d6b62d.html

Bytes ------------------------------------------------------------------------------------------------------

Private sub webbrowserappsdocumentcomplete (byval Pdisp as object, URL as variant)

For each sform in webbrowser1.document. Links

List1.additem sform

Next

End sub

Bytes -------------------------------------------------------------------------------------------------
Private sub webbrowserappsdocumentcomplete (byval Pdisp as object, URL as variant)
Dim X as long

For x = 0 to webbrowser1.document. Links. Length-1
Debug. Print webbrowser1.document. Links. Item (X)
Next x
The 'length' attribute returns the number of elements in the element set.
Debug. Print "Total" & webbrowser1.document. Links. Length & "links. "
End sub

Http://zhidao.baidu.com/question/69780769.html

Bytes ------------------------------------------------------------------------------------------

Dim dT as htmldocument
Set dt = webbrowser1.document
Me. Caption = DT. getelementsbytagname ("title") (0). innertext: displays the title Text of the webpage link.

Http://tieba.baidu.com/F? Kz= 255370663

 

[Cbm666 capture the title and URL of the webpage handle in progress]
Http://hi.baidu.com/cbm666/blog/item/9eec33fa9bd5d41ca9d3115d.html

 

'Project reference Microsoft Internet controls </P> <p> 'add command1 </P> <p> Option explicit <br/> private declare function getwindowtext lib "USER32" alias" getwindowtexta "(byval hwnd as long, byval lpstring as string, byval CCH as long) As long <br/> dim HW &, I % <br/> const maxlen = 255 <br/> Public mdocument as object <br/> private sub form_load () <br/> me. autoredraw = true <br/> me. width = 12000 <br/> me. move (screen. width-me. width)/2, (screen. height-me. height)/2 <br/> end sub </P> <p> private sub commandementclick () <br/> me. CLS <br/> call mcomgetiewindows <br/> end sub </P> <p> Public sub mcomgetiewindows () 'browser object set (including IE and Resource Manager) <br/> dim mshellwindow as new shdocvwctl. shellwindows 'cyclic variable <br/> for I = 0 to mshellwindow. count-1 <br/> If VBA. typename (mshellwindow. item (I ). document) = "htmldocument" then <br/> hW = mshellwindow. item (I ). hwnd <br/> Print CSTR (HW) & "" & getcaptionfromhwnd (HW) & "& mshellwindow. item (I ). document. URL <br/> end if <br/> next I <br/> end sub </P> <p> private function getcaptionfromhwnd (hwnd as long) as string <br/> dim strbuffer $, intcount %, JJ % <br/> strbuffer = string $ (maxlen-1, 0) <br/> intcount = getwindowtext (hwnd, strbuffer, maxlen) <br/> If intcount> 0 then <br/> JJ = instr (strbuffer, CHR (0) <br/> getcaptionfromhwnd = mid (strbuffer, 1, jj-1) <br/> end if <br/> end function <br/>

 

 'Add a webbrowser and a textbox <br/> private sub form_load () <br/> webbrowser1.navigate "http://www.tyzq.com.cn/pages/public/down.htm" <br/> end sub </P> <p> function getweburl (thehtml as webbrowser) as string <br/> getweburl = "" <br/> dim colllink <br/> set colllink = thehtml. document. all. tags ("A") <br/> for I = 0 to colllink. length-1 <br/> getweburl = getweburl & colllink (I) & vbcrlf <br/> next <br/> end function </P> <p> private sub webbrowser1_documentcomplete (byval Pdisp as object, URL as variant) <br/> text1.text = getweburl (webbrowser1) <br/> end sub

 

 

 

 

Details:

Private sub form_load ()
Inet1.execute "Your Website"
End sub

Private sub inetaskstatechanged (byval state as integer)
Dim stmp as string, shtml as string
If State = 12 then
Do
Doevents
Stmp = inet1.getchunk (1024)
If Len (stmp) = 0 Then exit do
Shtml = shtml + stmp
Loop
Text1.text = shtml
End if
End sub

This is a quick implementation.

Http://topic.csdn.net/t/20041205/15/3616650.html

 

 

How to obtain the webpage title using VB

It is almost used to complete the collection task! It's easy to contribute.
Function strcut (strcontent, strstart, strend) as string 'generic truncation Function
Dim strhtml, S1, S2 as string
Dim strstart, strend as string
Strhtml = strcontent
On Error resume next

S1 = instr (strhtml, strstart) + Len (strstart)
S2 = instr (S1, strhtml, strend)
Strcut = mid (strhtml, S1, S2-S1)

End Function

Private sub form_load ()
Dim hunzi1, hunzi2 as string
Hunzi1 = "<HTML> <title> This is Title </title> Hunzi2 = strcut (hunzi1, "<title>", "</title> ")
Msgbox hunzi2
End sub

 

 

Http://tieba.baidu.com/F? Kz= 255370663

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.