返回列表 上一主題 發帖

有關EXCEL VBA 抓取不到完整網址CSV問題

heavenweaver 您好
我目前有二個網址
http://www.gretai.org.tw/ch/stock/statistics/monthly/st42.php
都是屬於上述的狀況,我想請教一下,是否有工具可以查詢?edition=ch&filename=genpage/A" & YMD_day & ".dat&type=csv" --的參數資料出來呢,謝謝gto1208 發表於 2014-2-27 11:11

最直接的就是用瀏覽器本身所提供的網頁開發者工具如Chrome的檢查元素或FireFox的檢測元素
http://www.gretai.org.tw/ch/stock/statistics/monthly/st42.php

Request URL:http://www.gretai.org.tw/ch/stock/statistics/monthly/result_st42.php?timestamp=1393573668432
Form Data
            ajax=true&input_stock_code=3260
兩者合併
http://www.gretai.org.tw/ch/stock/statistics/monthly/result_st42.php?ajax=true&input_stock_code=3260

http://www.gretai.org.tw/ch/stock/statistics/monthly/st44.php

http://www.gretai.org.tw/ch/stock/statistics/monthly/result_st44.php?ajax=true&yy=2014&input_stock_code=3260
很抱歉,我是小學生,不能下載檔案,是個小屁孩!

TOP

謝謝heavenweaver,又學到一招了

TOP

回復  jak
GBKEE 發表於 2013-11-17 09:42


若是我想copy下列網址某天、某幾家的資料,http://stocker.com.tw/
可否請大大撥冗幫忙,有附檔

明細.rar (5.16 KB)

TOP

若是我想copy下列網址某天、某幾家的資料,http://stocker.com.tw/
可否請大大撥冗幫忙,有附檔
jak 發表於 2014/3/6 11:38

抱歉,沒有注意到,久等了.
試試看
  1. <input type="text" name="StoNum" id="StoNum" style="width:100px" value="1101" onkeyup="findStoNum()">
  2. '<input type="text" name="datestart" id="datepicker" style="width:80px" value="2014-05-09" class="hasDatepicker">
  3. '<input type="submit" class="senddata" value="提交">
  4. Option Explicit
  5. Dim FormDLL As String, xDate As Date, Sh As Worksheet ', Msg As Boolean
  6. Sub Ie_Table()
  7.     Dim URL As String, A As Object, i As Integer, E As Range
  8.     Set_FormDLL
  9.     URL = "http://stocker.com.tw/"
  10.     xDate = Date - 1
  11.     If Weekday(xDate, vbMonday) > 5 Then
  12.         Do While Weekday(xDate, vbMonday) > 5
  13.         xDate = xDate - 1
  14.         Loop
  15.     End If
  16.     Set Sh = Sheets.Add                   '結果顯示在新增的工作表
  17.     Sh.Name = Format(xDate, "yyyy-mm-dd") '命名為日期
  18.     With CreateObject("InternetExplorer.Application")
  19.         .navigate URL
  20.         .Visible = True
  21.         For Each E In Sheets("下載代號名單").Range("A3", Sheets("下載代號名單").[A3].End(xlDown))
  22.             Do While .Busy Or .ReadyState <> 4:         Loop
  23.             With .document.getElementsByTagName("input")
  24.                 .Item("StoNum").Value = E
  25.                 .Item("datestart").Value = Format(xDate, "yyyy-mm-dd")
  26.                 For i = 0 To .Length - 1
  27.                     If .Item(i).Type = "submit" Then .Item(i).Click
  28.                 Next
  29.             End With
  30.         Do While .Busy Or .ReadyState <> 4:         Loop
  31.         Set A = .document.getElementsByTagName("TABLE")
  32.         Ep A(A.Length - 1).outerHTML
  33.         Next
  34.         .Quit
  35.     End With
  36.     Remove_FormDLL
  37. End Sub
  38. Sub Ep(S As String)
  39.     Dim D As New DataObject, E As Shape
  40.     'DataObject 物件 在進行轉換動作時,做為格式化文字資料的暫存區域。其也可以暫存和儲存在 DataObject 的文字片段相關的格式。
  41.     '宣告 Dim D As New DataObject '須在工具-> 設定引用項目加入 新增引用 Microsoft Forms 2.0 Object Library ,專案 加入一表單即可
  42.     With D
  43.         .SetText S
  44.         .PutInClipboard
  45.         With Sh.UsedRange
  46.             If .Rows.Count = 1 Then
  47.                 .Cells(1).Select
  48.             Else
  49.                 .Rows(.Rows.Count).Cells(2).Select
  50.             End If
  51.             Sh.PasteSpecial Format:="Unicode 文字"
  52.              With ActiveCell
  53.                 .Cells(2, 1) = "日期"
  54.                 .Cells(3, 1).Resize(.Parent.UsedRange.Rows.Count - .Cells(3, 1).Row) = Format(xDate, "mm/dd")
  55.             End With
  56.             
  57.         End With
  58.     End With
  59. End Sub
  60. Sub Set_FormDLL()   '新增引用 Microsoft Forms 2.0 Object Library
  61.     On Error Resume Next
  62.     FormDLL = "FM20.DLL"
  63.     ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\FM20.DLL"
  64.     '"C:\windows\system32\"是2003版的路徑,2003以上版本需修改路徑
  65. End Sub
  66. Sub Remove_FormDLL() '刪除引用 Microsoft Forms 2.0 Object Library
  67.     Dim D As Object
  68.     For Each D In ThisWorkbook.VBProject.References
  69.         If UCase(D.fullpath) Like "*" & FormDLL Then
  70.             ThisWorkbook.VBProject.References.Remove D
  71.         End If
  72.     Next
  73. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 44# GBKEE

太神了,下載又快又穩,感謝大大幫忙,
還有抓下來的結果A欄是"日期",有沒有辦法改成該公司的"代號"呢?

TOP

本帖最後由 GBKEE 於 2014-5-25 16:31 編輯

回復 45# jak
  1. Sub Ie_Table()
  2. Ep A(A.Length - 1).outerHTML, E '修改一下
  3. End Sub
複製代碼
  1. Sub Ep(S As String, Code As Range)
  2.     Dim D As New DataObject ', E As Shape
  3.     'DataObject 物件 在進行轉換動作時,做為格式化文字資料的暫存區域。其也可以暫存和儲存在 DataObject 的文字片段相關的格式。
  4.     '宣告 Dim D As New DataObject '須在工具-> 設定引用項目加入 新增引用 Microsoft Forms 2.0 Object Library ,專案 加入一表單即可
  5.     With D
  6.         .SetText S
  7.         .PutInClipboard
  8.         With Sh.UsedRange
  9.             If .Rows.Count = 1 Then
  10.                 .Cells(1).Select
  11.             Else
  12.                 .Rows(.Rows.Count).Cells(2).Select
  13.             End If
  14.             Sh.PasteSpecial Format:="Unicode 文字"
  15.              With ActiveCell
  16.                 .Cells(2, 1) = "代號"
  17.                 .Cells(3, 1).Resize(.Parent.UsedRange.Rows.Count - .Cells(3, 1).Row) = Code
  18.             End With
  19.             
  20.         End With
  21.     End With
  22. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 jak 於 2014-5-24 19:11 編輯

回復 46# GBKEE
大大不好意思,這麼晚才回文,修改後執行出現錯誤,可以請大大看一下我哪裡放錯嗎?感謝
  1. Option Explicit
  2. Dim FormDLL As String, xDate As Date, Sh As Worksheet ', Msg As Boolean
  3. Sub Ie_Table()
  4.     Dim URL As String, A As Object, i As Integer, E As Range
  5.     Set_FormDLL
  6.     URL = "http://stocker.com.tw/"
  7.     xDate = Date - 1
  8.     If Weekday(xDate, vbMonday) > 5 Then
  9.         Do While Weekday(xDate, vbMonday) > 5
  10.         xDate = xDate - 1
  11.         Loop
  12.     End If
  13.     Set Sh = Sheets.Add                   '結果顯示在新增的工作表
  14.     Sh.Name = Format(xDate, "yyyy-mm-dd") '命名為日期
  15.     With CreateObject("InternetExplorer.Application")
  16.         .navigate URL
  17.         .Visible = True
  18.         For Each E In Sheets("下載代號名單").Range("A3", Sheets("下載代號名單").[A3].End(xlDown))
  19.             Do While .Busy Or .ReadyState <> 4:         Loop
  20.             With .document.getElementsByTagName("input")
  21.                 .Item("StoNum").Value = E
  22.                 .Item("datestart").Value = Format(xDate, "yyyy-mm-dd")
  23.                 For i = 0 To .Length - 1
  24.                     If .Item(i).Type = "submit" Then .Item(i).Click
  25.                 Next
  26.             End With
  27.         Do While .Busy Or .ReadyState <> 4:         Loop
  28.         Set A = .document.getElementsByTagName("TABLE")
  29.         Ep A(A.Length - 1).outerHTML, E '修改一下
  30.         Next
  31.         .Quit
  32.     End With
  33.     Remove_FormDLL
  34. End Sub
  35. Sub Ep(S As String, Code As StdFont)
  36.     Dim D As New DataObject, E As Shape
  37.     'DataObject 物件 在進行轉換動作時,做為格式化文字資料的暫存區域。其也可以暫存和儲存在 DataObject 的文字片段相關的格式。
  38.     '宣告 Dim D As New DataObject '須在工具-> 設定引用項目加入 新增引用 Microsoft Forms 2.0 Object Library ,專案 加入一表單即可
  39.     With D
  40.         .SetText S
  41.         .PutInClipboard
  42.         With Sh.UsedRange
  43.             If .Rows.Count = 1 Then
  44.                 .Cells(1).Select
  45.             Else
  46.                 .Rows(.Rows.Count).Cells(2).Select
  47.             End If
  48.             Sh.PasteSpecial Format:="Unicode 文字"
  49.              With ActiveCell
  50.                 .Cells(2, 1) = "代號"
  51.                 .Cells(3, 1).Resize(.Parent.UsedRange.Rows.Count - .Cells(3, 1).Row) = Code
  52.             End With
  53.             
  54.         End With
  55.     End With
  56. End Sub
  57. Sub Set_FormDLL()   '新增引用 Microsoft Forms 2.0 Object Library
  58.     On Error Resume Next
  59.     FormDLL = "FM20.DLL"
  60.     ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\FM20.DLL"
  61.     '"C:\windows\system32\"是2003版的路徑,2003以上版本需修改路徑
  62. End Sub
  63. Sub Remove_FormDLL() '刪除引用 Microsoft Forms 2.0 Object Library
  64.     Dim D As Object
  65.     For Each D In ThisWorkbook.VBProject.References
  66.         If UCase(D.fullpath) Like "*" & FormDLL Then
  67.             ThisWorkbook.VBProject.References.Remove D
  68.         End If
  69.     Next
  70. End Sub
複製代碼

TOP

回復 47# jak
不好意思,最近常犯錯.46#的程式碼已更新
  1. Sub Ep(S As String, Code As Range)
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 48# GBKEE
大大客氣了,要說不好意思的是我,這樣勞煩大大,
可以執行,結果就是我想像很久的樣子(按N個讚),太感謝了 ~~~

TOP

        靜思自在 : 要批評別人時,先想想自己是否完美無缺。
返回列表 上一主題