比如说我想采集一个网页的一些信息例如,采集网页  http://www.7song.cn/musiclist/7240.htm想用VB写段程序可以从该网页的HTML源代码里面截取“专辑名称:”后面的字符(就是专辑的名字)。这样的代码如何写?webshow.Caption = Inet1. _
OpenURL("http://www.7song.cn/musiclist/7240.htm")
Dim L As Long, j As Long, strTitle As String
L = InStr(LCase(webshow.Caption), "专辑名称:")
If L > 0 Then
  L = L + 5
  j = InStr(L, LCase(webshow.Caption), "</FONT>")
  If j > 0 Then
    '获取专辑名称
    strTitle = Mid(webshow.Caption, L, j - L)
    '下面是显示到 zhuanji(0):
    zhuanji(0).Caption = "专辑名称:" + strTitle
  Else
    '没有找到标签,提示错误
    MsgBox "无法获取标签!", vbExclamation, "错误"
  End If
Else
    '' 没有找到标签,提示错误
    MsgBox "无法获取标签!", vbExclamation, "错误"
End If
可是。这样根本无法正确采集。。
应该获取的地方的HTM代码:  <FONT color=#ff5a00>专辑名称:塔拉的神奇</FONT>
这样来看的话,第一个值写“专辑名称:”第二个值写“</FONT>”,就应该可以正确采集中间的部分,但是由于这个部位的前方也存在</FONT>标签,无法截取那我应该怎么办才能截取呢?我只是希望截取<FONT color=#ff5a00>专辑名称:塔拉的神奇</FONT>中间的哪个名字“阿拉的神奇”请高手解答

解决方案 »

  1.   

    L = InStr(webshow.Caption, "专辑名称:")
    if L = 0 then
      msgbox "Not found!"
      exit sub
    end if
    L = L + 5
    j = InStr(L, webshow.Caption, "</FONT>")msgbox mid(webshow.Caption, L, j - L)
      

  2.   

    你这样采集是没有用的``因为你用的转换小写的lcase.你要是把FONT改成font的话就可以采集到
    或者删了LCASE吧.呵````你这个代码给了我启发,有空交个朋友,我的QQ199962760
      

  3.   

    这个问题太简单了,给你个函数.
    Function urlpath3(filetext As String, str1 As String, str2 As String) As String  '''''不包含已知的两个搜索条件
    Dim s1 As Long, s2 As Long, str3 As String
       If Len(Trim(filetext)) > 0 Then
       'jxt = Split(filetext, str1)
        For i = 1 To Len(filetext)
         If Mid(filetext, i, Len(str1)) = str1 Then
          s1 = i + Len(str1)
         End If
          If Mid(filetext, i, Len(str2)) = str2 And s1 > 0 Then
           s2 = (i - s1)
          End If
           If s1 <> 0 And s2 <> 0 Then
            str3 = str3 & Trim(Mid(filetext, s1, Int(s2))) & vbCrLf
            s1 = 0
            s2 = 0
           End If
        Next
       End If
       urlpath3 = str3
      Exit Function
    End Function调用
    msgbox urlpath3(网页源代码,"专辑名称:","</FONT>")
    记得给分喔.
      

  4.   

    下面给出经过测试成功的代码.
    Private Sub Command1_Click()
    Dim a As String
    a = Inet1.OpenURL("http://www.7song.cn/musiclist/7240.htm")
    MsgBox urlpath3(a, "专辑名称:", "</FONT>")
    End Sub
    Function urlpath3(filetext As String, str1 As String, str2 As String) As String  '''''不包含已知的两个搜索条件
    Dim s1 As Long, s2 As Long, str3 As String
       If Len(Trim(filetext)) > 0 Then
        For i = 1 To Len(filetext)
         If Mid(filetext, i, Len(str1)) = str1 Then
          s1 = i + Len(str1)
         End If
          If Mid(filetext, i, Len(str2)) = str2 And s1 > 0 Then
           s2 = (i - s1)
          End If
           If s1 <> 0 And s2 <> 0 Then
            str3 = str3 & Trim(Mid(filetext, s1, Int(s2))) & vbCrLf
            s1 = 0
            s2 = 0
           End If
        Next
       End If
       urlpath3 = str3
      Exit Function
    End Function一定别忘了给分喔,另外提醒一下,要获取网页源代码,建议不要用openurl方法.
    因为一些比较长的源代码不会全部被提取的.
      

  5.   

    楼上的,如果有SESSION验证的,发如发送session.cookie