1个回答
展开全部
你好,(由于问题情境不充足,)这里假设你通过 Winsock 控件或 Internet Control 控件成功地获取网页源码并存储入变量 strCode 中。
然后可以参考以下思路:
' 注:该程序只能作为获取静态网页类型(*.htm/*.html)文件的链接。以下代码最好放入一个独立的函数中:
Dim l As Long, j As Long, lLen As Long
Dim strTmp As String, strTmp2 As String
Dim strLink As String, strLinkList As String
Dim bErr As Boolean
lLen = Len(strCode)
strTmp = LCase(strCode)
l = InStr(1, strTmp, "http://")
Do While l <> 0
For j = l + 7 To lLen - 1
strTmp2 = Mid(strTmp, j, 5)
If strTmp2 = ".html" Then ' 命中
strLink = Mid(strTmp, l, j - l + 5)
ElseIf strTmp2 Like ".htm?" ' 命中
strLink = Mid(strTmp, l, j - l + 4)
End If
Exit For
Next
If Len(strLink) Then
strLinkList = strLinkList & strLink & vbNewLine
strLink = Empty
Else ' 未命中
MsgBox "提示:该网页存在无效链接。", vbCritical, "注意"
'-----------------------------
' TODO: 如果要继续分析,则不编写代码
' 如果直接退出,则加入:
' bErr = True
' Exit Do
'-----------------------------
End If
l = InStr(l + 7, strTmp, "http://")
Loop
If bErr Then
MsgBox "程序运行时发生错误。", vbExclamation, "提示"
End If
然后可以参考以下思路:
' 注:该程序只能作为获取静态网页类型(*.htm/*.html)文件的链接。以下代码最好放入一个独立的函数中:
Dim l As Long, j As Long, lLen As Long
Dim strTmp As String, strTmp2 As String
Dim strLink As String, strLinkList As String
Dim bErr As Boolean
lLen = Len(strCode)
strTmp = LCase(strCode)
l = InStr(1, strTmp, "http://")
Do While l <> 0
For j = l + 7 To lLen - 1
strTmp2 = Mid(strTmp, j, 5)
If strTmp2 = ".html" Then ' 命中
strLink = Mid(strTmp, l, j - l + 5)
ElseIf strTmp2 Like ".htm?" ' 命中
strLink = Mid(strTmp, l, j - l + 4)
End If
Exit For
Next
If Len(strLink) Then
strLinkList = strLinkList & strLink & vbNewLine
strLink = Empty
Else ' 未命中
MsgBox "提示:该网页存在无效链接。", vbCritical, "注意"
'-----------------------------
' TODO: 如果要继续分析,则不编写代码
' 如果直接退出,则加入:
' bErr = True
' Exit Do
'-----------------------------
End If
l = InStr(l + 7, strTmp, "http://")
Loop
If bErr Then
MsgBox "程序运行时发生错误。", vbExclamation, "提示"
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询