|
楼主 |
发表于 2016-1-18 09:54
|
显示全部楼层
获取省、地市的代稍作更改:
Private Sub UserForm_Initialize()
Dim url, html, b, a, n
ComboBox1.Clear
url = "http://www.tianqihoubao.com/lishi/"
Set html = CreateObject("htmlfile")
With CreateObject("msxml2.xmlhttp")
.Open "get", url, False
.send
html.body.innerhtml = StrConv(.responseBody, vbUnicode, &H804)
For Each b In html.all.tags("b")
n = n + 1
ComboBox1.AddItem b.innertext
ComboBox1.List(n - 1, 1) = Replace(Replace(b.parentElement.href, "about:/lishi/", ""), ".htm", "") & ";"
For Each a In b.parentElement.parentElement.parentElement.ChildNodes(1).all.tags("a")
ComboBox1.List(n - 1, 1) = ComboBox1.List(n - 1, 1) & ":" & a.innertext
Next
Next
End With
ComboBox1.ListIndex = 0
End Sub
Private Sub ComboBox1_Change()
Dim url, html, b, a, n, t
ComboBox2.Clear
ComboBox3.Clear
url = Replace("http://www.tianqihoubao.com/lishi/代码.htm", "代码", Split(ComboBox1.List(ComboBox1.ListIndex, 1), ";")(0))
Set html = CreateObject("htmlfile")
Set html = CreateObject("htmlfile")
With CreateObject("msxml2.xmlhttp")
.Open "get", url, False
.send
html.body.innerhtml = StrConv(.responseBody, vbUnicode, &H804)
For Each b In html.all.tags("b")
n = n + 1
t = ""
'ComboBox2.AddItem b.innertext '因显示的是乱码,所以改用如下或拼音
ComboBox2.AddItem Split(ComboBox1.List(ComboBox1.ListIndex, 1), ":")(n)
'ComboBox2.AddItem Replace(Replace(b.parentElement.href, "about:/lishi/", ""), ".html", "") '改用拼音
For Each a In b.parentElement.parentElement.parentElement.ChildNodes(1).all.tags("a")
't = t & a.innertext & "," '因显示的是乱码,所以改用拼音
t = t & Replace(Replace(a.href, "about:/lishi/", ""), ".html", "") & ","
Next
ComboBox2.List(n - 1, 1) = t
Next
End With
ComboBox2.ListIndex = 0
End Sub
|
|