VBA_CSS定位元素

 1 Sub Css定位()
 2   
 3     Const url As String = "https://www.taifex.com.tw/cht/3/futDailyMarketReport" '期货每日交易行情查询
 4     Dim WinHttp As Object
 5     Dim Dom As New MSHTML.HTMLDocument 'Css只支持前期绑定
 6     
 7     Set WinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
 8     'Set Dom = CreateObject("htmlfile")
 9     
10     With WinHttp
11         .Open "GET", url, False
12         .Option(4) = 13056 'WinHttpRequestOption_SslErrorIgnoreFlags = 4 忽略证书失效错误
13         .send
14     
15         If .Status = 200 Then
16             Dom.body.innerHTML = .responsetext
17         End If
18     End With
19     '.>>>class #>>>id  chrome》console $()查询
20     Debug.Print Dom.querySelector("div").className 'copy js ==>document.querySelector("#btnTop") 第一个div
21     Debug.Print Dom.querySelector("div.title").innerText '标签div ,class = tile
22     Debug.Print Dom.querySelector("td > h3[align='left']").innerText
23     Debug.Print Dom.querySelectorAll("table.table_f tr th").Item(0).innerText
24     Debug.Print Dom.querySelectorAll("table tr th[colspan='11']").Item(0).innerText
25     Debug.Print Dom.querySelectorAll("select#commodity_idt > option").Item(1).innerText
26     Set WinHttp = Nothing
27     Set Dom = Nothing
28 
29 End Su

 

posted @ 2020-05-10 21:37  易塞尔工作室  阅读(554)  评论(0编辑  收藏  举报