转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
webbrowser 技巧2 (收藏)         ★★★★

webbrowser 技巧2 (收藏)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2558 更新时间:2009/4/23 15:03:40

取得网页中特定的链接
Private Sub Command1_Click()
    WebBrowser1.Navigate "http://www.95557.com/svote.htm"
End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    Dim a
   
    For Each a In WebBrowser1.Document.All
        If a.tagname = "A" Then
            If a.href = "http://tech.sina.com.cn/mobile/capture.shtml" Then
                a.Click
            End If
        End If
    Next
End Sub


Option Explicit
Private m_bDone As Boolean

Private Sub Command1_Click()
    If m_bDone Then
        Dim doc As IHTMLDocument2
        Set doc = WebBrowser1.Document
        Dim aLink As HTMLLinkElement
        Set aLink = doc.links(0)
        aLink.Click
    End If
End Sub

Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.95557.com/svote.htm"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    m_bDone = True
End Sub

==================================================

The following code can be used to query and delete files in the internet cache (including cookies). A demonstration routine can be found at the bottom of this post. Note, the enumerated type eCacheType is not supported in Excel 97, but can be changed to a list of Public Constants eg. Public Const eNormal = &H1&.
Option Explicit
''''--------------------------Types, consts and structures
Private Const ERROR_CACHE_FIND_FAIL As Long = 0
Private Const ERROR_CACHE_FIND_SUCCESS As Long = 1
Private Const ERROR_FILE_NOT_FOUND As Long = 2
Private Const ERROR_ACCESS_DENIED As Long = 5
Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122
Private Const MAX_CACHE_ENTRY_INFO_SIZE As Long = 4096
Private Const LMEM_FIXED As Long = &H0
Private Const LMEM_ZEROINIT As Long = &H40
Public Enum eCacheType
eNormal = &H1&
eEdited = &H8&
eTrackOffline = &H10&
eTrackOnline = &H20&
eSticky = &H40&
eSparse = &H10000
eCookie = &H100000
eURLHistory = &H200000
eURLFindDefaultFilter = 0&
End Enum
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
lpszSourceUrlName As Long
lpszLocalFileName As Long
CacheEntryType  As Long         ''''Type of entry returned
dwUseCount As Long
dwHitRate As Long
dwSizeLow As Long
dwSizeHigh As Long
LastModifiedTime As FILETIME
ExpireTime As FILETIME
LastAccessTime As FILETIME
LastSyncTime As FILETIME
lpHeaderInfo As Long
dwHeaderInfoSize As Long
lpszFileExtension As Long
dwExemptDelta  As Long
End Type
''''--------------------------Internet Cache API
Private Declare Function FindFirstUrlCacheEntry Lib "Wininet.dll" Alias "FindFirstUrlCacheEntryA" (ByVal lpszUrlSearchPattern As String, lpFirstCacheEntryInfo As Any, lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib "Wininet.dll" Alias "FindNextUrlCacheEntryA" (ByVal hEnumHandle As Long, lpNextCacheEntryInfo As Any, lpdwNextCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindCloseUrlCache Lib "Wininet.dll" (ByVal hEnumHandle As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
''''--------------------------Memory API
Private Declare Function LocalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal uBytes As Long) As Long
Private Declare Function LocalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function lstrcpyA Lib "kernel32" (ByVal RetVal As String, ByVal Ptr As Long) As Long
Private Declare Function lstrlenA Lib "kernel32" (ByVal Ptr As Any) As Long
''''Purpose     :  Deletes the specified internet cache file
''''Inputs      :  sCacheFile              The name of the cache file
''''Outputs     :  Returns True on success.
''''Author      :  Andrew Baker
''''Date        :  03/08/2000 19:14
''''Notes       :
''''Revisions   :
Function InternetDeleteCache(sCacheFile As String) As Boolean
InternetDeleteCache = CBool(DeleteUrlCacheEntry(sCacheFile))
End Function
''''Purpose     :  Returns an array of files stored in the internet cache
''''Inputs      :  eFilterType             An enum which filters the files returned by their type
''''Outputs     :  A one dimensional, one based, string array containing the names of the files
''''Author      :  Andrew Baker
''''Date        :  03/08/2000 19:14
''''Notes       :
''''Revisions   :
Function InternetCacheList(Optional eFilterType As eCacheType = eNormal) As Variant
Dim ICEI As INTERNET_CACHE_ENTRY_INFO
Dim lhFile As Long, lBufferSize As Long, lptrBuffer As Long
Dim sCacheFile As String
Dim asURLs() As String, lNumEntries As Long
''''Determine required buffer size
lBufferSize = 0
lhFile = FindFirstUrlCacheEntry(0&, ByVal 0&, lBufferSize)
If (lhFile = ERROR_CACHE_FIND_FAIL) And (Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then
''''Allocate memory for ICEI structure
lptrBuffer = LocalAlloc(LMEM_FIXED, lBufferSize)
If lptrBuffer Then
''''Set a Long pointer to the memory location
CopyMemory ByVal lptrBuffer, lBufferSize, 4
''''Call first find API passing it the pointer to the allocated memory
lhFile = FindFirstUrlCacheEntry(vbNullString, ByVal lptrBuffer, lBufferSize)        ''''1 = success
If lhFile <> ERROR_CACHE_FIND_FAIL Then
''''Loop through the cache
Do
''''Copy data back to structure
CopyMemory ICEI, ByVal lptrBuffer, Len(ICEI)
If ICEI.CacheEntryType And eFilterType Then
sCacheFile = StrFromPtrA(ICEI.lpszSourceUrlName)
lNumEntries = lNumEntries + 1
If lNumEntries = 1 Then
ReDim asURLs(1 To 1)
Else
ReDim Preserve asURLs(1 To lNumEntries)
End If
asURLs(lNumEntries) = sCacheFile
End If
''''Free memory associated with the last-retrieved file
Call LocalFree(lptrBuffer)
''''Call FindNextUrlCacheEntry with buffer size set to 0.
''''Call will fail and return required buffer size.
lBufferSize = 0
Call FindNextUrlCacheEntry(lhFile, ByVal 0&, lBufferSize)
''''Allocate and assign the memory to the pointer
lptrBuffer = LocalAlloc(LMEM_FIXED, lBufferSize)
CopyMemory ByVal lptrBuffer, lBufferSize, 4&
Loop While FindNextUrlCacheEntry(lhFile, ByVal lptrBuffer, lBufferSize)
End If
End If
End If
''''Free memory
Call LocalFree(lptrBuffer)
Call FindCloseUrlCache(lhFile)
InternetCacheList = asURLs
End Function
''''Purpose     :  Converts a pointer an ansi string into a string.
''''Inputs      :  lptrString                  A long pointer to a string held in memory
''''Outputs     :  The string held at the specified memory address
''''Author      :  Andrew Baker
''''Date        :  03/08/2000 19:14
''''Notes       :
''''Revisions   :
Function StrFromPtrA(ByVal lptrString As Long) As String
''''Create buffer
StrFromPtrA = String$(lstrlenA(ByVal lptrString), 0)
''''Copy memory
Call lstrcpyA(ByVal StrFromPtrA, ByVal lptrString)
End Function
''''Demonstration routine
Sub Test()
Dim avURLs As Variant, vThisValue As Variant
On Error Resume Next
''''Return an array of all internet cache files
avURLs = InternetCacheList
For Each vThisValue In avURLs
''''Print files
Debug.Print CStr(vThisValue)
Next
''''Return the an array of all cookies
avURLs = InternetCacheList(eCookie)
If MsgBox("Delete cookies?", vbQuestion + vbYesNo) = vbYes Then
For Each vThisValue In avURLs
''''Delete cookies
InternetDeleteCache CStr(vThisValue)
Debug.Print "Deleted " & vThisValue
Next
Else
For Each vThisValue In avURLs
''''Print cookie files
Debug.Print vThisValue
Next
End If
End Sub


=======================================================
分析网页内容,取得<SCRIPT>
Option Explicit

Private Sub Form_Load()
    WebBrowser1.Navigate "http://test/index.html"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Varian

[1] [2] [3] [4]  下一页


[C语言系列]怎么使用webbrowser获取页面中的button元素。并触…  [C语言系列]C#实现 WebBrowser中新窗口打开链接用默认或者指定…
[C语言系列]c#WebBrowser查找并选择文本  [C语言系列]利用Webbrowser修改里的html代码里全部的"link"替…
[C语言系列]C#清除IE缓存临时文件实现WebBrowser强制刷新  [C语言系列]一个参数解决应用程序中WebBrowser的缓存问题
[C语言系列]自动关闭webBrowser弹出的所有窗口  [C语言系列]WebBrowser在同一个窗口打开网页,禁止在新窗口打…
[Web开发]c# tabcontrol webbrowser 新标签页打开超链接  [C语言系列]C# webBrowser强制在本窗口打开,禁止在新窗口打开
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台