vb获取网页的所有元素
原来获取网页的所有元素是这么简单: Dim theHTML As New HTMLDocument Set theHTML = wb.document ' wb = ActiveX WebBrowser ' theHTML.All 就是它了! ……所以获得所有链接也就易如反掌了!: Dim collLink As IHTMLElementCollection ' Get all links Set collLink = theHTML.All.tags("a") For i = 0 To collLink.length - 1 Debug.Print "Link " & CStr(i + 1) & ": " & collLink(i) & vbNewLine Next 相信以后会征服所有的html元素! |
http://hi.baidu.com/ok100fen/blog/item/34cdea1d2f27fc8c87d6b62d.html
------------------------------------------------------------------------------------------------------
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
For Each sform In WebBrowser1.Document.links
List1.AddItem sform
Next
End Sub
-------------------------------------------------------------------------------------------------
Private Sub WebBrowser1_DocumentComplete(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
'length属性返回元素集中元素的个数
Debug.Print "共有" & WebBrowser1.Document.links.length & "个链接。"
End Sub
http://zhidao.baidu.com/question/69780769.html
------------------------------------------------------------------------------------------
Dim dt As HTMLDocument
Set dt = WebBrowser1.Document
Me.Caption = dt.getElementsByTagName("title")(0).innerText ’显示网页链接的标题文字信息
http://tieba.baidu.com/f?kz=255370663
【CBM666 捕获运行中的网页句柄标题与URL】
http://hi.baidu.com/cbm666/blog/item/9eec33fa9bd5d41ca9d3115d.html
'工程中引用Microsoft Internet Controls '添加 Command1 Option Explicit Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Dim hw&, i% Const MAXLEN = 255 Public mDocument As Object Private Sub Form_Load() Me.AutoRedraw = True Me.Width = 12000 Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 End Sub Private Sub Command1_Click() Me.Cls Call mComGetIEWindows End Sub Public Sub mComGetIEWindows() '浏览器对象集合(包含IE也包含资源管理器) Dim mShellWindow As New SHDocVwctl.ShellWindows '循环变量 For i = 0 To mShellWindow.Count - 1 If VBA.TypeName(mShellWindow.Item(i).Document) = "HTMLDocument" Then hw = mShellWindow.Item(i).hwnd Print CStr(hw) & " " & GetCaptionFromHwnd(hw) & " " & mShellWindow.Item(i).Document.url End If Next i End Sub Private Function GetCaptionFromHwnd(hwnd As Long) As String Dim strBuffer$, intCount%, jj% strBuffer = String$(MAXLEN - 1, 0) intCount = GetWindowText(hwnd, strBuffer, MAXLEN) If intCount > 0 Then jj = InStr(strBuffer, Chr(0)) GetCaptionFromHwnd = Mid(strBuffer, 1, jj - 1) End If End Function
'添加一个WebBrowser,一个textbox Private Sub Form_Load() WebBrowser1.Navigate "http://www.tyzq.com.cn/pages/public/down.htm" End Sub Function GetWebUrl(theHTML As WebBrowser) As String GetWebUrl = "" Dim collLink Set collLink = theHTML.Document.All.tags("a") For i = 0 To collLink.length - 1 GetWebUrl = GetWebUrl & collLink(i) & vbCrLf Next End Function Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) Text1.Text = GetWebUrl(WebBrowser1) End Sub
具体:
Private Sub Form_Load()
Inet1.Execute "你的网址 "
End Sub
Private Sub Inet1_StateChanged(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
这样实现起来很快的。
http://topic.csdn.net/t/20041205/15/3616650.html
用vb怎么获取网页标题
几乎都用它来完成采集任务了!贡献出来啊,很简单滴
Function strCut(strContent, StrStart, StrEnd) As String '通用截取函数
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 = "
http://tieba.baidu.com/f?kz=255370663