- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2016-8-20 09:49
| 只看該作者
本帖最後由 GBKEE 於 2016-8-20 10:09 編輯
回復 1# PKKO
試試看- Option Explicit
- Const Img = "d:\Tel.jpg"
- Sub Ex_()
- Dim i As Integer, E As Object, a, St As String, x As Integer, Sh As Worksheet
- St = "search/"
- Set Sh = ActiveSheet
- With Sh
- .Cells.Clear
- .Pictures.Delete
- .Columns("A:A").ColumnWidth = 29.25
- .Columns("B:B").ColumnWidth = 33.13
- .Columns("C:C").ColumnWidth = 28.5
- .Cells.RowHeight = 19.5
- End With
- With CreateObject("InternetExplorer.Application")
- .Visible = True
- .Navigate "https://www.iyp.com.tw/search.php?a_id=5&k=%E9%A4%90%E5%BB%B3"
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- With .Document
- For Each a In .getElementByID("search-res").all.TAGS("LI")
- If a.ID <> "" Then
- i = i + 1
- With a
- Sh.Cells(i, "a") = .all.TAGS("A")(0).INNERTEXT
- Sh.Cells(i, "d") = .all.TAGS("A")(0).href
- Set E = .all.TAGS("SPAN")(2)
- With Sh.Cells(i, "B")
- .Cells = Split(E.outerHTML, """>")(0)
- x = InStr(.Cells, St)
- .Cells = Mid(.Cells, x + Len(St))
- End With
- 下載網路圖片 .all.TAGS("IMG")(0).href
- With Sh.Cells(i, "C")
- .Select
- Set E = Sh.Pictures.Insert(Img)
- E.Height = .Cells.Height '照片的右方在工作表上的位置
- E.Width = .Cells.Width
- End With
- End With
- End If
- Next
- End With
- .Quit '關閉網頁
- End With
- If Dir(Img) <> "" Then Kill Img
- End Sub
- Private Sub 下載網路圖片(Url As String)
- Dim xml As Object '用來取得網頁資料
- Dim stream 'As ADODB.stream '用來儲存二進位檔案
- Set xml = CreateObject("Microsoft.XMLHTTP")
- Set stream = CreateObject("ADODB.stream")
- xml.Open "GET", Url, 0
- xml.send
- With stream
- .Open
- .Type = 1
- .write xml.ResponseBody
- If Dir(Img) <> "" Then Kill Img
- .SaveToFile (Img)
- .Close
- End With
- End Sub
複製代碼 |
|