VB中text1.text 在网页中获取了这么一段代码
<td>2007-11-01</td><td>江北区</td><td>可吸入颗粒物</td><td>67</td><td>Ⅱ</td><td>良</td><td><img src=./pic/classcolor2.jpg border=0 ></td>
</tr><tr style="color:Black;background-color:Gainsboro;">
<td>2007-11-01</td><td>沙坪坝区</td><td>可吸入颗粒物</td><td>76</td><td>Ⅱ</td><td>良</td><td><img src=./pic/classcolor2.jpg border=0 ></td> 是一个表格的代码的一段
网地:http://www.cqemc.cn/rbsearch.aspx
其中地点名 比如 地名是不变的 其他的都要变
我想把根据上面的代码
获取数据然后保存至变量 比如 a(1)="江北区"
b(1)="可吸入颗粒物"
c(1)=67
d(1)=Ⅱ
c(1)=良 a(2)="沙坪坝区"
b(2)=吸入颗粒物
c(1)=76
d(1)=Ⅱ
c(1)=良 怎么才能提取下来
<td>2007-11-01</td><td>江北区</td><td>可吸入颗粒物</td><td>67</td><td>Ⅱ</td><td>良</td><td><img src=./pic/classcolor2.jpg border=0 ></td>
</tr><tr style="color:Black;background-color:Gainsboro;">
<td>2007-11-01</td><td>沙坪坝区</td><td>可吸入颗粒物</td><td>76</td><td>Ⅱ</td><td>良</td><td><img src=./pic/classcolor2.jpg border=0 ></td> 是一个表格的代码的一段
网地:http://www.cqemc.cn/rbsearch.aspx
其中地点名 比如 地名是不变的 其他的都要变
我想把根据上面的代码
获取数据然后保存至变量 比如 a(1)="江北区"
b(1)="可吸入颗粒物"
c(1)=67
d(1)=Ⅱ
c(1)=良 a(2)="沙坪坝区"
b(2)=吸入颗粒物
c(1)=76
d(1)=Ⅱ
c(1)=良 怎么才能提取下来
这个应该不难解决。
先建立5个数组dim a(10) as string
dim b(10) as string
dim c(10) as string
dim d(10) as string
dim e(10) as string
1、“站点名称”在日期后的第二个td处;
2、首要污染物"可吸入颗粒物"在地名后的第二个td处;
3、API指数在“首要污染物”后的第二个td处;
4、质量级别在“API指数”后的第二个td处;
5、质量状况在“质量级别”后的第二个td处;
很有规律嘛!
dim b(10) as string
dim c(10) as string
dim d(10) as string
dim e(10) as string
dim s as string
s=text.texta(1)=mid(s,InStr(s,"</td><td>")+len("</td><td>"),8)
'站点名称的最大长度,比如是8。然后再去掉其他不要的字符
replace(s,"</td><td>",space(9))
a(2)=mid(s,InStr(s,"</td><td>")+len("</td><td>"),2)
'API指数2位
replace(s,"</td><td>",space(9))
.
.
.
以此类推
Dim strTmp As String
Dim p1 As Integer, p2 As Integer
Dim strItems() As StringDim a() As String, b() As String, c() As String, d() As String, e() As String
Dim i As Integer, n As IntegerstrSource = "<td> 2007-11-01 </td> <td> 江北区 </td> <td> 可吸入颗粒物 </td> <td> 67 </td> <td> Ⅱ </td> <td> 良 </td> <td> <img src=./pic/classcolor2.jpg border=0 > </td> </tr> <tr style= ""color:Black;background-color:Gainsboro; ""> <td> 2007-11-01 </td> <td> 沙坪坝区 </td> <td> 可吸入颗粒物 </td> <td> 76 </td> <td> Ⅱ </td> <td> 良 </td> <td> <img src=./pic/classcolor2.jpg border=0 > </td>"
strTmp = Replace(strSource, "<td>", "")
strTmp = Replace(strTmp, "</td>", "")
strTmp = Replace(strTmp, "</tr>", "")p1 = InStr(strTmp, "<img")
Do While p1
p2 = InStr(p1, strTmp, ">")
strTmp = Left(strTmp, p1 - 1) & Mid(strTmp, p2 + 1)
p1 = InStr(strTmp, "<img")
LoopDo While InStr(strTmp, Space(2))
strTmp = Replace(strTmp, Space(2), Space(1))
Loopp1 = InStr(strTmp, "<tr style")
Do While p1
p2 = InStr(p1, strTmp, ">")
strTmp = Left(strTmp, p1 - 1) & Mid(strTmp, p2 + 1)
p1 = InStr(strTmp, "<tr style")
LoopDo While InStr(strTmp, Space(2))
strTmp = Replace(strTmp, Space(2), Space(1))
LoopstrItems = Split(Trim(strTmp), Space(1))n = (UBound(strItems) + 1) / 6ReDim a(1 To n)
ReDim b(1 To n)
ReDim c(1 To n)
ReDim d(1 To n)
ReDim e(1 To n)For i = 1 To n
a(i) = strItems((i - 1) * 6 + 1)
b(i) = strItems((i - 1) * 6 + 2)
c(i) = strItems((i - 1) * 6 + 3)
d(i) = strItems((i - 1) * 6 + 4)
e(i) = strItems((i - 1) * 6 + 5)
Next iFor i = 1 To n
Debug.Print a(i), b(i), c(i), d(i), e(i)
Next i结果:
江北区 可吸入颗粒物 67 Ⅱ 良
沙坪坝区 可吸入颗粒物 76 Ⅱ 良
顺便说下我的解决方案
Text1.Text = Inet1.OpenURL("http://www.cqemc.cn/rbsearch.aspx")
th = "</font></td><td><font color=""Black"">"
a = Split(Text1.Text, th)
for b=1 to 100'新建立一个FOR循环读取
msgbox a(b) & "a(" & b & ")"
next然后看下a(b)的数值就知道该数值在数组中的位置了嘿嘿.是自己想出来的 不过楼上的各位好象的方法都比我强些
通过这个例子体会了一点 方法是有很多的