|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 onlycxb 于 2014-10-22 08:31 编辑
作业2、网站:http://www.caac.gov.cn/S1/GNCX/, 操作:点击“查询”,获取航班信息数据。- 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-22&DT=7&BD=&BT=7&AL=ALL&DR=true&image.x=37&image.y=9&Sn=87bf24142bc0c78727610871f373e0a7"
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Open "GET", Url, False
- .Send
- St = .responsetext
- End With
- '
- 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) = Split(Split(St, "<strong>")(1), "</strong>")(0)
- arr = Split(St, "<div class=""menu_layout2"">") '航空公司分组
- For i = 1 To UBound(arr)
- S1 = arr(i)
- Crr = Split(S1, "<div class=""listtwo_layout"">")
- ReDim brr(1 To UBound(Crr) + 2, 1 To 5) '班次UBound(S1) + 1,航空公司及机行+1,航线+1
- '航空公司
- brr(1, 1) = Trim(Split(Split(S1, "<div class=""menu_top1"">")(1), "</div>")(0)) '中国东方航空公司
- brr(1, 2) = Trim(Split(Split(S1, "<div class=""menu_top2"">")(1), "</div>")(0)) '航班
- brr(1, 2) = Trim(Split(Split(brr(1, 2), "font"">")(1), "</span>")(0))
- brr(1, 3) = Trim(Split(Split(S1, "<div class=""menu_top2"">")(2), "</div>")(0)) ''机型:333
- '飞行线路
-
- brr(2, 1) = Trim(Split(Split(S1, "<div class=""menu1_layout"">")(1), "</div>")(0)) '北京首都机场
- brr(2, 2) = Trim(Split(Split(S1, "<div class=""menu2_layout"">")(1), "</div>")(0)) '(22:00)
- brr(2, 3) = Trim(Split(Split(S1, "<div class=""menu3_layout"">")(1), "</div>")(0)) '经停:0
- brr(2, 4) = Trim(Split(Split(S1, "<div class=""menu1_layout"">")(2), "</div>")(0)) '上海虹桥机场
- brr(2, 5) = Trim(Split(Split(S1, "<div class=""menu2_layout"">")(2), "</div>")(0)) '(23:55)
- '飞行班次
- For j = 1 To UBound(Crr)
- S2 = Crr(j)
- ' Debug.Print S2
- brr(2 + j, 1) = Trim(Split(Split(S2, "<div class=""menu4_layout"">")(1), "</div>")(0)) '票价
- brr(2 + j, 2) = Trim(Split(Split(S2, "<div class=""menu5_layout"">")(1), "</div>")(0)) '舱位'
- brr(2 + j, 3) = Trim(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), 5) = brr
-
- Next i
- End With
- End If
- End Sub
复制代码 '顺便把航空公司抓了一下
- Sub 作业1_2_航空公司获取()
- '网站:http://www.caac.gov.cn/S1/GNCX/
- '操作:点击“查询”,获取航班信息数据。
- Dim strText As String
- With CreateObject("MSXML2.XMLHTTP")
- .Open "GET", "http://www.caac.gov.cn/images/airlinecontrol.js", False
- .Send
- strText = .responsetext
- Debug.Print ByteToStr(.responseBody, "GB2312")
- End With
- End Sub
- Function ByteToStr(arrByte, strCharset As String) As String
- With CreateObject("Adodb.Stream")
- .Type = 1 'adTypeBinary
- .Open
- .Write arrByte
- .Position = 0
- .Type = 2 'adTypeText
- .Charset = strCharset
- ByteToStr = .Readtext
- .Close
- End With
- End Function
复制代码 |
评分
-
3
查看全部评分
-
|