作者skart (Darren )
看板Visual_Basic
標題[VBA ] 模擬IE,如何抓取有下拉式選單資料?
時間Tue Dec 7 15:26:50 2021
1.使用軟體:Excel VBA
2.網址:
https://goodinfo.tw/StockInfo/StockBzPerformance.asp?STOCK_ID=2108
3.想抓取的網頁資料:網頁裡的PER/PBR資料表格(如圖
https://reurl.cc/52AG9V)
4.抓取資料到 資料表 B4
5.自己寫的程式碼,不知哪裡有錯?
Sub 巨集1()
'
'
'
Dim url As String
Dim IE As Object
Dim i, j As Integer
Cells.Clear
'第2步驟 建立IE
Set IE = CreateObject("InternetExplorer.application")
url = "
https://goodinfo.tw/StockInfo/StockBzPerformance.asp?STOCK_ID=2108"
With IE
.Visible = True
.navigate url
Do While .Busy Or .ReadyState <> 4
Loop
'第2步驟 底選下拉式選單
Set HtmlDoc = .document
HtmlDoc.getElementByname("ChgFinDetailSheet(this.value);")(0).selectedindex = 3
'第3步驟 存入儲存個B4
i = 4
For Each nRow In Motable.Rows
j = 2
For Each nCol In nRow.Cells
Cells(i, j) = nCol.innertext
j = j + 1
Next
i = i + 1
Next
.Quit
End With
'
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.216.222.35 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Visual_Basic/M.1638862013.A.20E.html
1F:推 lossa35: getelement"s"byname可能少打s 04/13 12:17