作者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/cn.aspx?n=bbs/Visual_Basic/M.1638862013.A.20E.html
1F:推 lossa35: getelement"s"byname可能少打s 04/13 12:17