У меня следующий код HTML на 17track. net:
<div class="tools"> <button type="button" class="btn btn-sm icon fa-copy-files-o waves-
effect" data-toggle="tooltip" data-placement="top" data-original-title="Copy detailed
tracking results for all numbers." id="cl-details" data-clipboard-text="Number:
LW571320552CN
Package status: Delivered (26 Days)
Country: China -> United States
Destination:
2020-04-02 13:03, CATAWBA, SC 29704, Delivered, In/At Mailbox -> Your item was delivered in
or at the mailbox at 1:03 pm on April 2, 2020 in CATAWBA, SC 29704.
2020-04-02 08:13, CATAWBA, SC 29704, Out for Delivery
2020-04-02 08:02, CATAWBA, SC 29704, Arrived at Unit
2020-04-01 10:59, MID CAROLINA-CHARLOTTE NC DISTRIBUTION CENTER, Arrived at USPS Regional
Destination Facility
2020-03-31 00:00, In Transit to Next Facility
2020-03-30 10:02, ALBANY NY DISTRIBUTION CENTER, Arrived at USPS Regional Facility
2020-03-28 09:54, ISC NEW YORK NY(USPS), Processed Through Facility
2020-03-28 09:54, Origin Post is Preparing Shipment
По сути, мне просто нужно получить статус пакета. Я также могу согласиться с этим, просто вставив весь текст в Excel, и затем я могу проанализировать его с помощью VBA. По какой-то причине мой код VBA не работает, чтобы получить это с помощью простой очистки. Я новичок в HTML, поэтому спасибо за вашу помощь.
Sub TrackData()
Dim element As IHTMLElement
Dim elements As IHTMLElementCollection
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://t.17track.net/en#nums=LW572098229CN"
'Wait until IE has loaded the web page
Do While ie.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set html = ie.document
Set elements = html.getElementsByClassName("tools")
Dim count As Long
Dim erow As Long
count = 0
For Each element In elements
If element.Children = "Package Status:" Then
Sheets("Stage").Cells(1, 1) = "Found It"
End If
Next element
End Sub