|
本帖最后由 onlycxb 于 2014-10-28 23:45 编辑
- 不断修改不断完善中!
- Sub 作业1_2_获取航班信息数据()
- '网站:http://www.caac.gov.cn/S1/GNCX/
- '操作:点击“查询”,获取航班信息数据。
- Dim St As String, Url$, arr, brr, Crr, sntxt
- Dim S1$, S2$, i%, j%, rng As Range, Flydate As Date
- Flydate = #11/21/2014# '查询飞行日期
- '取第一个sn=出现的网址相关数据
- Url = "http://webflight.linkosky.com/WEB/Flight/WaitingSearch.aspx?JT=1&OC=PEK&DC=SHA&dstDesp=GUANGZHOU%B9%E3%D6%DD&dst2=CAN&DD=" & Format(Flydate, "yyyy-mm-dd") & "&DT=7&BD=&BT=7&AL=ALL&DR=true&image.x=44&image.y=11"
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Open "GET", Url, False
- .setRequestHeader "Referer", "http://www.caac.gov.cn/S1/GNCX/"
- .Send
- sntxt = Split(Split(.responsetext, "window.location.replace('")(1), "'")(0)
- Debug.Print sntxt
- .Open "GET", "http://webflight.linkosky.com" & sntxt, False
- .setRequestHeader "Referer", "http://www.caac.gov.cn/S1/GNCX/"
- .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
复制代码 |
|