【发布时间】:2020-11-21 23:39:32
【问题描述】:
我正在使用 VBA 进行网页抓取。下面是html结构和我的VBA代码。
当我运行它时,我得到了这个文本ETA : 2020-08-26 (Reference only, the date will be updated according to shipments).
但我只想从中刮取日期2020-08-26
<div style="font-size: 14px;">
<span class="label" style="font-weight: bolder; font-size: 13px;">ETA : </span>
<br>
2020-08-26
<span style="color: red; font-size: 12px;">(Reference only, the date will be updated according to
shipments).</span>
</div>
VBA 代码>
Dim ie As New InternetExplorer
Dim doc As New HTMLDocument
ie.navigate "http://127.0.0.1/wordpress/sample-page/"
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Set elems = doc.getElementsByTagName("div")
MsgBox elems(33).innerText
【问题讨论】:
-
获得完整字符串后,使用
Instr和Mid定位:和(的位置以隔离日期,然后使用Trim删除前导和尾随空格,然后将其设置为日期变量。
标签: excel vba web-scraping excel-2007