|
本帖最后由 onlycxb 于 2014-10-28 23:47 编辑
- 此楼可直接跳过,看265楼
- 干了一天的活,挤出一点时间更正一下44楼代码。取出多项数据。现在还有一个问题,就是Sn=4a8649481e59583f006f592ca003f6da,这个代码如何得到,这个目前未知,有知道的希望告知。
- Sub 作业1_2_获取航班信息数据()
- '网站:http://www.caac.gov.cn/S1/GNCX/
- '操作:点击“查询”,获取航班信息数据。
- Dim St As String, Url$, arr, brr, Crr
- Dim S1$, S2$, i%, j%, rng As Range
- Url = "http://webflight.linkosky.com/WEB/Flight/FlightSearchResultDefault.aspx?JT=1&OC=PEK&DC=SHA&dstDesp=GUANGZHOU%B9%E3%D6%DD&dst2=CAN&DD=2014-10-28&DT=7&BD=&BT=7&AL=ALL&DR=true&image.x=35&image.y=14&Sn=4a8649481e59583f006f592ca003f6da"
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Open "GET", Url, False
- .Send
- St = .responsetext
- End With
- Cells.Clear
- '
- If InStr(St, "<div id=""FlightListFlight0"">") < 1 Then
- Cells(1, 1) = "抱歉!没有满足条件的航班,请重新输入查询条件! "
- Else
- St = Split(Split(St, "<div id=""FlightListFlight0"">")(1), "</div><br>")(0)
- With ActiveSheet
- Cells(1, 1).Resize(1, 3).Merge
- Cells(2, 1).Resize(1, 3).Merge
- Cells(1, 1).Resize(1, 3) = Split(Split(St, "<div class=""menu_layout3""><strong>")(1), "<")(0) '选择去程(北京首都---上海虹桥)航班
- Cells(2, 1).Resize(1, 3) = Split(Split(St, "<div class=""layout2_title3"">")(1), "<")(0) '北京首都至上海虹桥 出发日期:2014-10-28
- arr = Split(St, "<div class=""menu_layout2"">")
- For i = 1 To UBound(arr)
- S1 = arr(i)
- Crr = Split(S1, "<div class=""menu4_layout"">")
- ReDim brr(1 To UBound(Crr) - 1 + 3, 1 To 3) '
- brr(1, 1) = Trim(Split(Split(S1, "<div class=""menu_top1"">")(1), "<")(0)) '航空公司
- brr(1, 2) = Trim(Split(Split(S1, "<div class=""menu_top2""> <strong><span class=""red_font"">")(1), "<")(0)) '航班
- brr(1, 3) = Split(Split(S1, "<div class=""menu_top2"">")(2), "<")(0) '机型
- For j = 2 To UBound(Crr)
- S2 = Crr(j)
- brr(j, 1) = Split(S2, "</div>")(0)
- brr(j, 2) = Split(Split(S2, "<div class=""menu5_layout"">")(1), "</div>")(0)
- brr(j, 3) = Split(Split(S2, "<div class=""menu6_layout"">")(1), "</div>")(0)
- Next j
- Set rng = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
- rng.Resize(UBound(brr, 1), UBound(brr, 2)) = brr
- Next i
- End With
- End If
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|