返回列表 上一主題 發帖

請問這個網頁如何用WEB查詢輸入excel

本帖最後由 GBKEE 於 2013-11-18 14:16 編輯

回復 20# joey0415
.document(文件).body(本體).innerHTML(代碼,文字) = .document.getElementById("queryResult").outerHTML(輸出的:代碼,文字)
可在這行程式碼設下中斷點,看一下網頁前後的變化
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 c_c_lai 於 2013-11-18 15:27 編輯

回復 18# stillfish00
請教一下,我把 .Navigate "http://portal.sw.nat.gov.tw/APGQ/GB315" 換成
.Navigate "http://portal.sw.nat.gov.tw/APGQ/GB309" 出口報單通關流程查詢

  1.        Set x = .document.getElementById("myform").getElementsByTagName("input")
  2.         x(2).Value = sID     '  填入號碼    (原本為 x(0).Value = sID )
  3.         x(11).Click          '  查詢        (原本為 x(1).Click )
複製代碼
執行到 ActiveSheet.PasteSpecial Format:="HTML" 卻發生了錯誤訊息,
請問應如何修正方屬正確? 謝謝你!

TOP

本帖最後由 GBKEE 於 2013-11-18 16:06 編輯

回復 22# c_c_lai
  1. For Each x In .document.getElementsByTagName("input")
  2.              If x.Name = "declNo" Then x.Value = sID
  3.             If x.Value = "查詢" Then x.Click
  4.         Next
複製代碼
這行也要修改 =0
  1. If InStr(sStatus, "[執行成功]") = 0 Then .Quit: MsgBox sStatus: Exit Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 23# GBKEE
多謝了!
正當我測試完成時,正好亦看到您送來的訊息,
對我幫助甚大,亦將您的註釋加入並應用,
再次言謝!
  1. Sub 出口報單放行單查詢結果()
  2.     Dim sID As String, sStatus As String
  3.     Dim x
  4.    
  5.     sID = InputBox("出口報單號碼", "出口報單放行資料查詢", "BE  02XE580024")
  6.     If sID = "" Then Exit Sub
  7.    
  8.     With CreateObject("InternetExplorer.Application")
  9.         .Visible = True     '  是否顯示 IE
  10.         .Navigate "http://portal.sw.nat.gov.tw/APGQ/GB309"
  11.         
  12.         Do While .readyState <> 4
  13.             DoEvents
  14.         Loop
  15.       
  16.         '  Set x = .document.getElementById("myform").getElementsByTagName("input")
  17.         '  x(1).Value = sID     '  填入號碼  ("declNo")
  18.         '  x(10).Click          '  查詢      ("查詢")
  19.         '  對於 x 的運用,此上下兩種表達方式決果一致;然下列方式可避免判斷上之誤判情事。
  20.         For Each x In .document.getElementsByTagName("input")
  21.             If x.Name = "declNo" Then x.Value = sID
  22.             If x.Value = "查詢" Then x.Click
  23.         Next
  24.         
  25.         Do While .document.getElementById("statusMsg").Value = ""
  26.             DoEvents
  27.         Loop
  28.       
  29.         sStatus = .document.getElementById("statusMsg").Value
  30.         If InStr(sStatus, "[執行成功]") <= 0 Then .Quit: MsgBox sStatus: Exit Sub
  31.                               
  32.         .document.body.innerHTML = .document.getElementById("queryResult").outerHTML
  33.         .execwb 17, 2       '  Select All
  34.         .execwb 12, 2       '  Copy selection
  35.                
  36.         ActiveSheet.[A1].Select
  37.         ActiveSheet.PasteSpecial Format:="HTML"     ', NoHTMLFormatting:=True
  38.         .Quit
  39.     End With
  40. End Sub
複製代碼

TOP

回復  joey0415
.document(文件).body(本體).innerHTML(代碼,文字) = .document.getElementById("queryRe ...
GBKEE 發表於 2013-11-18 14:13

補充一下 innerHTML 和 outerHTML 不同:
    .getElementById("queryResult").outerHTML 是指包含自身標籤的html代碼,如  <table id="queryResult"><tr>blahblah..</tr></table>
    .getElementById("queryResult").innerHTML 是不包含自身標籤,只有內部的html代碼,即<tr>blahblah..</tr>

TOP

回復 25# stillfish00
感謝補足說明
回復 24# c_c_lai
如果這些 出口報單放行單查詢的網頁相類似的可如此 (改一下stillfish00的程式碼)
  1. Option Explicit
  2. Sub 出口查詢()
  3.     Dim sID As String, sStatus As String, URL As String
  4.     Dim x
  5.     URL = InputBox("1:出口報單放行資料查詢(產證專用)(GB315)" & vbLf & "2:出口報單通關流程查詢(GB309)", "出口資料查詢", 1)
  6.     If URL = "" Or (URL <> "1" And URL <> "2") Then Exit Sub
  7.     URL = IIf(URL = "1", "GB315", "GB309")
  8.     sID = InputBox("出口報單號碼", "出口報單放行資料" & URL & "查詢", "BE  02XE580024")
  9.     If sID = "" Then Exit Sub
  10.     URL = "http://portal.sw.nat.gov.tw/APGQ/" & URL & "?&declNo=" & sID   
  11.     With CreateObject("InternetExplorer.Application")
  12.         .Visible = True     '  是否顯示 IE
  13.         .Navigate URL
  14.         Do While .readyState <> 4
  15.             DoEvents
  16.         Loop
  17.         For Each x In .document.getElementsByTagName("input")
  18.             If x.Value = "查詢" Then x.Click: Exit For
  19.         Next
  20.         Do While .document.getElementById("statusMsg").Value = ""
  21.             DoEvents
  22.         Loop
  23.         sStatus = .document.getElementById("statusMsg").Value
  24.         If InStr(sStatus, "[執行成功]") <= 0 Then .Quit: MsgBox sStatus: Exit Sub
  25.                               
  26.         .document.body.innerHTML = .document.getElementById("queryResult").outerHTML
  27.         .execwb 17, 2       '  Select All
  28.         .execwb 12, 2       '  Copy selection
  29.         With ActiveSheet
  30.             .Cells.Clear
  31.             .[A1].Select
  32.             .PasteSpecial Format:="HTML"
  33.         End With
  34.         .Quit
  35.     End With
  36. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 26# GBKEE
彙整的蠻貼心的,在尾端我順便加上了自動調整蘭寬的處裡。
  1.         With ActiveSheet
  2.             .Cells.Clear
  3.             .[A1].Select
  4.             .PasteSpecial Format:="HTML"
  5.             .Cells.EntireColumn.AutoFit     '  自動調整欄寬
  6.         End With
複製代碼
謝謝囉!

TOP

本帖最後由 joey0415 於 2013-11-18 22:04 編輯

回復 26# GBKEE

請問超級版主

以這方式來抓鉅享網來練習時,程式碼如下
  1.     Sub TEST11()
  2.         Dim x   
  3.         With CreateObject("InternetExplorer.Application")
  4.             .Visible = True '是否顯示IE
  5.             .Navigate "http://www.cnyes.com/twstock/Institutional/1101.htm"
  6.             Do While .readyState <> 4: DoEvents: Loop
  7.             Set x = .document.getElementById("a_itrust")
  8.             x.Click  
  9.             Do While .readyState <> 4: DoEvents: Loop
  10.             .document.body.innerHTML = .document.getElementById("tabvl").outerHTML
  11.             .execwb 17, 2 'Select All
  12.             .execwb 12, 2 'Copy selection
  13.             ActiveSheet.[A1].Select
  14.             ActiveSheet.PasteSpecial Format:="HTML" ', NoHTMLFormatting:=True
  15.             .Quit
  16.         End With
  17.     End Sub
複製代碼
到這一行會出錯,如圖
.document.body.innerHTML = .document.getElementById("tabvl").outerHTML

我以鉅亨網中的投信進出為例子練習

再問一個困擾很久的問題
.getElementById與.getElementsByTagName
有些有id與tagname 有些只有id ,有些只有tagname
請問有先後從屬的關係嗎?

若有父子關係把子設為x的話,那父層就不能表示嗎?還是先父層再加一個  「點」

若這樣設x=.document.getElementById("tabvl") 出錯

請版主指點一下

TOP

回復 28# joey0415
試試這個:
  1. Sub 鉅享網()
  2.     Dim sID As String, sStatus As String, URL As String
  3.     Dim x
  4.    
  5.     URL = "http://www.cnyes.com/twstock/Institutional/1101.htm"
  6.     With CreateObject("InternetExplorer.Application")
  7.         .Visible = True     '  是否顯示 IE
  8.         .Navigate URL
  9.         
  10.         Do While .readyState <> 4
  11.             DoEvents
  12.         Loop
  13.         
  14.         For Each x In .Document.getelementsbytagname("input")
  15.             If x.Value = "查詢" Then x.Click: Exit For
  16.         Next
  17.                
  18.         .Document.body.innerHTML = .Document.getelementsbytagname("table")(1).outerHTML
  19.         .execwb 17, 2       '  Select All
  20.         .execwb 12, 2       '  Copy selection
  21.         
  22.         With ActiveSheet
  23.             .Cells.Clear
  24.             .[A2].Select
  25.             .PasteSpecial Format:="HTML"
  26.             .Cells.EntireColumn.AutoFit     '  自動調整欄寬
  27.         End With
  28.         .Quit
  29.     End With
  30. End Sub
複製代碼

TOP

回復 28# joey0415
因為我的 FireFox 無法使用上傳圖片與附件,所以才另外用 IE 上傳

TOP

        靜思自在 : 慈悲沒有敵人,智慧不起煩惱。
返回列表 上一主題