返回列表 上一主題 發帖

請問如何將網頁的圖片存檔

請問如何將網頁的圖片存檔

With CreateObject("InternetExplorer.application")           
        .Visible = True                                       
        .Navigate "http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/brokerBS.php?l=zh-tw"
      
        Do Until .ReadyState = 4               
            DoEvents
        Loop
Set img = .document.all.tags("img")(0)
end with
請問我如何把img這個圖存成c:\2.png

感謝GBKEE大大的回答!
Private Sub 網路圖片存檔(img As String)
    Dim xml As Object     '用來取得網頁資料
    Dim stream            'As ADODB.stream   '用來儲存二進位檔案
    Set xml = CreateObject("Microsoft.XMLHTTP")
    Set stream = CreateObject("ADODB.stream")
    xml.Open "GET", img, 0
    xml.send
    With stream
        .Open
        .Type = 1
        .write xml.ResponseBody
        If Dir(圖形) <> "" Then Kill 圖形
        .SaveToFile (圖形)
        .Close
    End With
End Sub
以這方式下載的圖片與IE頁面的圖不是相同的圖
要如何下載回來的是IE頁面的圖,因為它是PNG檔
我試了幾種方式都沒辦法是IE頁面的圖,驗證碼的
圖要轉成BMP格式才能做2值化的處理.如果不是PNG
檔的話用GetClipboardData就可以處理了!一直想
破頭個人的功力實在太淺了還在學習中!希望老師
能提點一下!

TOP

測試完發現驗證碼輸入頁面上的碼與存檔圖上的碼都是OK的??

TOP

下載的圖片與IE頁面的圖不是相同的圖
導入都會"驗證碼已逾期,請重新查詢"
失敗!如何抓下來圖是ie頁面顯示的圖片咧?

TOP

原來是驗證碼tessdata-OCR視別錯誤!

TOP

Sheets("上櫃股票").Activate
    With CreateObject("InternetExplorer.application")           '創建一個空的ie
        .Visible = True                                         '讓ie可見
        .Navigate "http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/brokerBS.php?l=zh-tw"
        Do Until .ReadyState = 4               '等待ie完畢載入
            DoEvents
        Loop
         code = InputBox("輸入驗證碼", "code", code)
        For Each stock In Range([a2], [a65536].End(xlUp))'股票代號

        .Document.ALL("stk_code").Value = stock '填寫股票代號
        .Document.ALL("auth_num").Value = code '填寫驗證碼
     
    With Sheets("web")
      .Cells.Delete
      .QueryTables.Add Connection:="URL;", Destination:=.Range("A1")
      
    With .QueryTables.Add(Connection:="URL;http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/download_ALLCSV.php?curstk=" & stock & "&stk_date=" & 日期 & "&auth=" & code & "", Destination:=.[a1])
        .AdjustColumnWidth = False
        .WebFormatting = xlWebFormattingNone
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
    End With
   
    .Columns("A:A").TextToColumns Destination:=.Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1)), _
        TrailingMinusNumbers:=True
        
    End With
End With
上櫃驗證碼有60秒的有效性,只要打個10來次就可下載完!

TOP

Sheets("上櫃股票").Activate
    With CreateObject("InternetExplorer.application")           '創建一個空的ie
        .Visible = True                                         '讓ie可見
        .Navigate "http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/brokerBS.php?l=zh-tw"
      
        Do Until .ReadyState = 4               '等待ie完畢載入
            DoEvents
        Loop
       code = InputBox("輸入查詢code", "code", code)
        For Each stock In Range([a2], [a65536].End(xlUp))
        .document.All("stk_code").Value = stock
        .document.All("auth_num").Value = code 'Cells(1, 1)
   
    With Sheets("web")
    .Cells.Delete
      .QueryTables.Add Connection:="URL;", Destination:=.Range("A1")
       DoEvents
    With .QueryTables.Add(Connection:="URL;http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/download_ALLCSV.php?curstk=" & stock & "&stk_date=" & 日期 & "&auth=" & code & "", Destination:=.[a1])
        .AdjustColumnWidth = False
        .WebFormatting = xlWebFormattingNone
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
    End With
   
    .Columns("A:A").TextToColumns Destination:=.Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1)), _
        TrailingMinusNumbers:=True
        If .[a4] = " " Then .Cells.Delete: GoTo a
    End With
        If Sheets("web").[a4] = "驗證碼已逾期,請重新查詢" Then
        stock.Offset(, 2) = "ng"
        .Quit
        
        .Visible = True                                         '讓ie可見
        .Navigate "http://www.gretai.org.tw/web/stock/aftertrading/broker_trading/brokerBS.php?l=zh-tw"
        Do Until .ReadyState = 4               '等待ie完畢載入
            DoEvents
        Loop
      
         code = InputBox("輸入查詢code", "code", code)
                GoTo a
        End If
    整頁下載    '資訊整理
    a:
     Next
      End With
程序很亂相互參考一下!

TOP

        靜思自在 : 信心、毅力、勇氣三者具備,則天下沒有做不成的事。
返回列表 上一主題