VB 获取网页的内容
获取一个PHP网页的内容<dtclass="name">初音未来</dt><ddclass="thumb"><imgsrc="data/upload/skin/20081...
获取一个PHP网页的内容
<dt class="name">初音未来</dt>
<dd class="thumb"><img src="data/upload/skin/20081129/112964231.jpg" width='256' height="384" alt="" /></dd>
<dd class="btnList"><a href="down_skin.php?id=470"><img src="images/btn_download.gif" alt="download" /></a></dd>
<dd class="desc"><label>档案大小:</label> 46427 Bytes</dd>
<dd class="desc"><label>登记日期:</label> 2008-11-29 06:10:31</dd>
<dd class="desc"><label>说 明:</label> 初音大爱啊!!!本人NB的卷发</dd>
<dd class="desc"><label>作 者:</label> g7541025</dd>
<!--<dd class="desc"><label>修改日期:</label> 2008-07-07 11:08:49</dd>-->
<dd class="desc"><label>下载次数:</label> 114</dd>
</dl> 展开
<dt class="name">初音未来</dt>
<dd class="thumb"><img src="data/upload/skin/20081129/112964231.jpg" width='256' height="384" alt="" /></dd>
<dd class="btnList"><a href="down_skin.php?id=470"><img src="images/btn_download.gif" alt="download" /></a></dd>
<dd class="desc"><label>档案大小:</label> 46427 Bytes</dd>
<dd class="desc"><label>登记日期:</label> 2008-11-29 06:10:31</dd>
<dd class="desc"><label>说 明:</label> 初音大爱啊!!!本人NB的卷发</dd>
<dd class="desc"><label>作 者:</label> g7541025</dd>
<!--<dd class="desc"><label>修改日期:</label> 2008-07-07 11:08:49</dd>-->
<dd class="desc"><label>下载次数:</label> 114</dd>
</dl> 展开
6个回答
展开全部
给你几个函数,可以从网络获取网页内容,是用VBA编的,移植到VB里去应该没问题,要把变量名称改成英文的。试一下吧,不行找我QQ99137479
Private Declare Function socket Lib "WS2_32.dll" (ByVal af As Long, ByVal lType As Long, ByVal protocol As Long) As Long
Private Declare Function closesocket Lib "WS2_32.dll" (ByVal s As Long) As Long
Private Declare Function WSAStartup Lib "WS2_32.dll" (ByVal wVersionRequired As Integer, ByRef lpWSAData As WSAData) As Long
Private Declare Function inet_addr Lib "WS2_32.dll" (ByVal cp As String) As Long
Private Declare Function connect Lib "WS2_32.dll" (ByVal s As Long, ByRef name As sockaddr, ByVal namelen As Long) As Long
Private Declare Function htons Lib "WS2_32.dll" (ByVal hostshort As Integer) As Integer
Private Declare Function send Lib "WS2_32.dll" (ByVal s As Long, ByVal buf As String, ByVal lLen As Long, ByVal flags As Long) As Long
Private Declare Function recv Lib "WS2_32.dll" (ByVal s As Long, buf As Any, ByVal lLen As Long, ByVal flags As Long) As Long
Private Declare Function WSACleanup Lib "WS2_32.dll" () As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
'Private Declare Function getsockopt Lib "WS2_32.dll" (ByVal s As Integer, ByVal level As Integer, ByVal optname As Integer, optval As Any, optlen As Integer) As Integer
Private Declare Function getsockopt Lib "WS2_32.dll" (ByVal s As Long, ByVal level As Long, ByVal optname As Long, ByVal optval As String, ByRef optlen As Long) As Long
Private Declare Function WSAGetLastError Lib "WS2_32.dll" () As Long
Private Declare Function selectws Lib "WS2_32.dll" Alias "select" (ByVal nfds As Long, ByRef readfds As fd_set, ByVal wrITefds As Long, ByVal exceptfds As Long, ByRef timeout As timeval) As Long
Private Const AF_INET As Long = 2
Private Const INVALID_SOCKET As Long = Not 0
Private Const IPPROTO_TCP As Long = 6
Private Const MIN_SOCKETS_REQD = 1
Private Const SOCKET_ERROR = -1
Private Const SOCK_STREAM As Long = 1
Private Const WS_VERSION_REQD = &H101
Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128
Private Const SO_MAX_MSG_SIZE As Long = &H2003
Private Const SOL_SOCKET As Long = &HFFFF&
Private Const WSAEMSGSIZE As Long = 10040&
Private Type WSAData
wVersion As Integer
wHighVersion As Integer
szDescription As String * WSADescription_Len
szSystemStatus As String * WSASYS_Status_Len
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Private Type sockaddr
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
Private Type fd_set
fd_count As Integer
fd_array(64) As Integer
End Type
Private Type timeval
tv_sec As Long
tv_usec As Long
End Type
Private Type HostEnt
h_name As Long
h_aliASEs As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Function 截取两个标志间的内容(原文 As String, 指针 As Long, 标志1 As String, 标志2 As String) As String
Dim 指针1 As Long
指针 = InStr(指针, 原文, 标志1, vbBinaryCompare)
If 指针 = 0 Then Exit Function
指针 = 指针 + Len(标志1)
指针1 = InStr(指针, 原文, 标志2, vbBinaryCompare)
If 指针1 = 0 Then Exit Function
If 指针1 >= 指针 Then 截取两个标志间的内容 = Mid(原文, 指针, 指针1 - 指针)
End Function
Function 发送网络信息(IP地址 As String, 端口 As String, 信息 As String) As String
Const 接收长度 = 16384
Dim 整形返回码 As Integer, 长形返回码 As Long, 接收缓冲区() As Byte, MyWSAData As WSAData, 地址 As sockaddr, 网络接口 As Long, s As String, fd As fd_set, time As timeval
整形返回码 = WSAStartup(WS_VERSION_REQD, MyWSAData)
网络接口 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
地址.sin_family = AF_INET
地址.sin_port = htons(Val(端口))
地址.sin_addr = inet_addr(IP地址)
整形返回码 = connect(网络接口, 地址, Len(地址))
' ReDim 接收缓冲区(1 To 100) As Byte
' If getsockopt(网络接口, SOL_SOCKET, SO_MAX_MSG_SIZE, s, 100) <> 0 Then
' Debug.Print WSAGetLastError
' End If
整形返回码 = send(网络接口, 信息, Len(信息), 0)
' fd.fd_count = 1: fd.fd_array(0) = 网络接口
' time.tv_sec = 5: time.tv_usec = 0
' Debug.Print selectws(0, 0, 0, 0, 0, time)
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
If 整形返回码 = -1 Then Exit Function
While 整形返回码 > 0
Debug.Print 整形返回码
发送网络信息 = 发送网络信息 & StrConv(接收缓冲区, vbUnicode)
发送网络信息 = Replace(发送网络信息, Chr(0), "", , , vbBinaryCompare)
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
Wend
长形返回码 = closesocket(网络接口)
整形返回码 = WSACleanup
ReDim 接收缓冲区(0) As Byte
End Function
Function 接收文件(IP地址 As String, 端口 As String, 信息 As String) As String
Const 接收长度 = 16384
Dim 整形返回码 As Integer, 长形返回码 As Long, 接收缓冲区() As Byte, MyWSAData As WSAData, 地址 As sockaddr, 网络接口 As Long, 临时字串 As String, 头长度 As Integer, 文件长度 As Long, 指针 As Long, i As Long
整形返回码 = WSAStartup(WS_VERSION_REQD, MyWSAData)
网络接口 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
地址.sin_family = AF_INET
地址.sin_port = htons(Val(端口))
地址.sin_addr = inet_addr(IP地址)
整形返回码 = connect(网络接口, 地址, Len(地址))
整形返回码 = send(网络接口, 信息, Len(信息), 0)
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
If 整形返回码 = -1 Then Exit Function
临时字串 = StrConv(接收缓冲区, vbUnicode)
头长度 = InStr(1, 临时字串, "close" & vbCr & vbLf, vbBinaryCompare) + 9
临时字串 = 截取两个标志间的内容(临时字串, 1, "filename=", vbCr & vbLf)
接收文件 = 临时字串
Open 周报路径 & "全省周报\周汇总\" & 临时字串 For Binary Access Write As #1
For i = 头长度 To 整形返回码
Put #1, i - 头长度 + 1, 接收缓冲区(i)
Next
指针 = 整形返回码 - 头长度 + 2
Do
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
If 整形返回码 = 0 Then Exit Do
ReDim Preserve 接收缓冲区(1 To 整形返回码) As Byte
Put #1, 指针, 接收缓冲区()
指针 = 指针 + 整形返回码
Loop
长形返回码 = closesocket(网络接口)
整形返回码 = WSACleanup
ReDim 接收缓冲区(0) As Byte
Close #1
End Function
Private Declare Function socket Lib "WS2_32.dll" (ByVal af As Long, ByVal lType As Long, ByVal protocol As Long) As Long
Private Declare Function closesocket Lib "WS2_32.dll" (ByVal s As Long) As Long
Private Declare Function WSAStartup Lib "WS2_32.dll" (ByVal wVersionRequired As Integer, ByRef lpWSAData As WSAData) As Long
Private Declare Function inet_addr Lib "WS2_32.dll" (ByVal cp As String) As Long
Private Declare Function connect Lib "WS2_32.dll" (ByVal s As Long, ByRef name As sockaddr, ByVal namelen As Long) As Long
Private Declare Function htons Lib "WS2_32.dll" (ByVal hostshort As Integer) As Integer
Private Declare Function send Lib "WS2_32.dll" (ByVal s As Long, ByVal buf As String, ByVal lLen As Long, ByVal flags As Long) As Long
Private Declare Function recv Lib "WS2_32.dll" (ByVal s As Long, buf As Any, ByVal lLen As Long, ByVal flags As Long) As Long
Private Declare Function WSACleanup Lib "WS2_32.dll" () As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
'Private Declare Function getsockopt Lib "WS2_32.dll" (ByVal s As Integer, ByVal level As Integer, ByVal optname As Integer, optval As Any, optlen As Integer) As Integer
Private Declare Function getsockopt Lib "WS2_32.dll" (ByVal s As Long, ByVal level As Long, ByVal optname As Long, ByVal optval As String, ByRef optlen As Long) As Long
Private Declare Function WSAGetLastError Lib "WS2_32.dll" () As Long
Private Declare Function selectws Lib "WS2_32.dll" Alias "select" (ByVal nfds As Long, ByRef readfds As fd_set, ByVal wrITefds As Long, ByVal exceptfds As Long, ByRef timeout As timeval) As Long
Private Const AF_INET As Long = 2
Private Const INVALID_SOCKET As Long = Not 0
Private Const IPPROTO_TCP As Long = 6
Private Const MIN_SOCKETS_REQD = 1
Private Const SOCKET_ERROR = -1
Private Const SOCK_STREAM As Long = 1
Private Const WS_VERSION_REQD = &H101
Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128
Private Const SO_MAX_MSG_SIZE As Long = &H2003
Private Const SOL_SOCKET As Long = &HFFFF&
Private Const WSAEMSGSIZE As Long = 10040&
Private Type WSAData
wVersion As Integer
wHighVersion As Integer
szDescription As String * WSADescription_Len
szSystemStatus As String * WSASYS_Status_Len
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Private Type sockaddr
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
Private Type fd_set
fd_count As Integer
fd_array(64) As Integer
End Type
Private Type timeval
tv_sec As Long
tv_usec As Long
End Type
Private Type HostEnt
h_name As Long
h_aliASEs As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Function 截取两个标志间的内容(原文 As String, 指针 As Long, 标志1 As String, 标志2 As String) As String
Dim 指针1 As Long
指针 = InStr(指针, 原文, 标志1, vbBinaryCompare)
If 指针 = 0 Then Exit Function
指针 = 指针 + Len(标志1)
指针1 = InStr(指针, 原文, 标志2, vbBinaryCompare)
If 指针1 = 0 Then Exit Function
If 指针1 >= 指针 Then 截取两个标志间的内容 = Mid(原文, 指针, 指针1 - 指针)
End Function
Function 发送网络信息(IP地址 As String, 端口 As String, 信息 As String) As String
Const 接收长度 = 16384
Dim 整形返回码 As Integer, 长形返回码 As Long, 接收缓冲区() As Byte, MyWSAData As WSAData, 地址 As sockaddr, 网络接口 As Long, s As String, fd As fd_set, time As timeval
整形返回码 = WSAStartup(WS_VERSION_REQD, MyWSAData)
网络接口 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
地址.sin_family = AF_INET
地址.sin_port = htons(Val(端口))
地址.sin_addr = inet_addr(IP地址)
整形返回码 = connect(网络接口, 地址, Len(地址))
' ReDim 接收缓冲区(1 To 100) As Byte
' If getsockopt(网络接口, SOL_SOCKET, SO_MAX_MSG_SIZE, s, 100) <> 0 Then
' Debug.Print WSAGetLastError
' End If
整形返回码 = send(网络接口, 信息, Len(信息), 0)
' fd.fd_count = 1: fd.fd_array(0) = 网络接口
' time.tv_sec = 5: time.tv_usec = 0
' Debug.Print selectws(0, 0, 0, 0, 0, time)
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
If 整形返回码 = -1 Then Exit Function
While 整形返回码 > 0
Debug.Print 整形返回码
发送网络信息 = 发送网络信息 & StrConv(接收缓冲区, vbUnicode)
发送网络信息 = Replace(发送网络信息, Chr(0), "", , , vbBinaryCompare)
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
Wend
长形返回码 = closesocket(网络接口)
整形返回码 = WSACleanup
ReDim 接收缓冲区(0) As Byte
End Function
Function 接收文件(IP地址 As String, 端口 As String, 信息 As String) As String
Const 接收长度 = 16384
Dim 整形返回码 As Integer, 长形返回码 As Long, 接收缓冲区() As Byte, MyWSAData As WSAData, 地址 As sockaddr, 网络接口 As Long, 临时字串 As String, 头长度 As Integer, 文件长度 As Long, 指针 As Long, i As Long
整形返回码 = WSAStartup(WS_VERSION_REQD, MyWSAData)
网络接口 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
地址.sin_family = AF_INET
地址.sin_port = htons(Val(端口))
地址.sin_addr = inet_addr(IP地址)
整形返回码 = connect(网络接口, 地址, Len(地址))
整形返回码 = send(网络接口, 信息, Len(信息), 0)
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
If 整形返回码 = -1 Then Exit Function
临时字串 = StrConv(接收缓冲区, vbUnicode)
头长度 = InStr(1, 临时字串, "close" & vbCr & vbLf, vbBinaryCompare) + 9
临时字串 = 截取两个标志间的内容(临时字串, 1, "filename=", vbCr & vbLf)
接收文件 = 临时字串
Open 周报路径 & "全省周报\周汇总\" & 临时字串 For Binary Access Write As #1
For i = 头长度 To 整形返回码
Put #1, i - 头长度 + 1, 接收缓冲区(i)
Next
指针 = 整形返回码 - 头长度 + 2
Do
ReDim 接收缓冲区(1 To 接收长度) As Byte
整形返回码 = recv(网络接口, 接收缓冲区(1), 接收长度, 0)
If 整形返回码 = 0 Then Exit Do
ReDim Preserve 接收缓冲区(1 To 整形返回码) As Byte
Put #1, 指针, 接收缓冲区()
指针 = 指针 + 整形返回码
Loop
长形返回码 = closesocket(网络接口)
整形返回码 = WSACleanup
ReDim 接收缓冲区(0) As Byte
Close #1
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
系统是自带浏览器控件的,浏览器控件有很多的函数,msdn 上有函数的说明,网上也有很多vb做的浏览器demo 下下看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
具体点,你想获取网页里面的什么内容?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
太复杂了,不懂!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
winsock控件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询