比如说我想采集一个网页的一些信息例如,采集网页 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>中间的哪个名字“阿拉的神奇”请高手解答
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>中间的哪个名字“阿拉的神奇”请高手解答
解决方案 »
- VB 拦截 IE 发出去的POST参数, 修改后发送
- xp下可以使用wmi设置工作组名称和计算机名吗
- LISTVIEW能不能做成象组合框那样可以下拉选择的形式
- mHeji <> mDanjia * mQty
- 119问题,急急急!!!感谢各位帮忙
- 动态生成控件,如何动态去掉?(在线等!)
- 请问高手如果要接收计算机串口传来的数据(通过定期刷新)在VB里应该调用什么函数?
- 如何使windows的所有程序都置于后台,无法对它们进行操作?高手们一展才华的良机来了!
- 关于sendmessage,相信大家都想知道,UP者也有分
- 请问哪里有Crystal Report报表设计器?高分送上。我的D版中怎么没有?
- VB Winsock控件怎样向广播地址发信息?
- 我想打开服务器上的word文档,服务器有用户密码,文件夹也开了共享,如何打开word
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)
或者删了LCASE吧.呵````你这个代码给了我启发,有空交个朋友,我的QQ199962760
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>")
记得给分喔.
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方法.
因为一些比较长的源代码不会全部被提取的.