- 帖子
- 1018
- 主題
- 15
- 精華
- 0
- 積分
- 1058
- 點名
- 0
- 作業系統
- win7 32bit
- 軟體版本
- Office 2016 64-bit
- 閱讀權限
- 50
- 性別
- 男
- 來自
- 桃園
- 註冊時間
- 2012-5-9
- 最後登錄
- 2022-9-28
|
回復 23# sujane0701
Python 絕對是值得學習的語言,較熱門,套件也多。
參考 VBALearner 的 code ,改為 VBA 的 code 應該也是能達到你的需求的:- Sub 查詢()
- Dim oXmlhttp: Set oXmlhttp = CreateObject("msxml2.xmlhttp")
- Dim oHtml: Set oHtml = CreateObject("htmlfile")
- Dim sUrl As String, sPost As String, sID As String
- Dim ar, r, i, j
-
- With Sheets(1)
- ar = .[a1].Resize(.Cells(.Rows.Count, 1).End(xlUp).Row)
- End With
- For r = 2 To UBound(ar)
- sID = ar(r, 1)
- With oXmlhttp
- sUrl = "https://accs.tradevan.com.tw/accsw-bin/APACCS/userLoginAction.do?userid=GUEST&password=GUEST"
- .Open "Get", sUrl, False
- .send
- oHtml.Body.innerhtml = .responsetext
- sUrl = "https://accs.tradevan.com.tw/accsw-bin/APACCS/cImMergeQueryAction.do"
- sPost = "mawb_no=" & sID & "&查詢=查詢"
- sPost = oHtml.parentWindow.encodeURI(sPost)
- .Open "Post", sUrl, False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .setRequestHeader "Content-Length", Len(sPost)
- .send (sPost)
- oHtml.Body.innerhtml = .responsetext
- With oHtml.GetElementsByTagName("table")(4).Rows(1)
- sInfo = .Cells(.Cells.Length - 1).GetElementsByTagName("a")(0).href
- End With
-
- sUrl = "https://accs.tradevan.com.tw/accsw-bin/APACCS/cImMergeListAction.do"
- sPost = "mawb_no=" & sID & _
- "&voyage_flight_no=" & Split(Split(sInfo, "flight_no=")(1), "&")(0) & _
- "&flight_date=" & Split(Split(sInfo, "flight_date=")(1), "&")(0) & _
- "&est_arrival_date=" & Split(Split(sInfo, "est_arrival_date=")(1), "&")(0) & _
- "&qry_mawb_no=" & sID & _
- "&qry_sort=0"
- sPost = oHtml.parentWindow.encodeURI(sPost)
- .Open "Post", sUrl, False
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .setRequestHeader "Content-Length", Len(sPost)
- .send (sPost)
- oHtml.Body.innerhtml = .responsetext
- With oHtml.GetElementsByTagName("table")(4)
- For i = 0 To .Rows.Length - 1
- With .Rows(i)
- For j = 0 To .Cells.Length - 1
- Sheets(2).Cells((r - 2) * 12 + i + 1, j + 1).Value = .Cells(j).innertext
- Next
- End With
- Next
- End With
- End With
- Next
- End Sub
複製代碼 |
|