我正在查看此网页 -> https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=671299425542&locale=en_US&cntry_code=us
我想返回交货日期 2016 年 3 月 31 日星期四中午 12:16
这是我到目前为止的代码
Public Sub FedExTracking()
Dim IE As Object
Dim ReturnValue As Object
Dim ProUrl As String
Dim RowCount As Integer
Dim PullText As String
Dim iCounter As Integer
Set IE = CreateObject("InternetExplorer.application")
RowCount = 0
Do While Not ActiveCell.Offset(RowCount, -1).Value = ""
ProUrl = "https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=" & ActiveCell.Offset(RowCount, -1).Value & "&locale=en_US&cntry_code=us"
With IE
.Visible = True
.Navigate ProUrl
Do Until Not IE.Busy And IE.readyState = 4: DoEvents: Loop
End With
iCounter = 0
Do While iCounter < 8
WaitHalfSec
iCounter = iCounter + 1
Loop
set ReturnValue = IE.document.getElementsClassName("snapshotController_date.dest")(0)
'THIS LINE RETURNS RUN TIME ERROR "91" OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET
PullText = ReturnValue.innertext
ActiveCell.Offset(RowCount).Value = PullText & "."
RowCount = RowCount + 1
Loop
IE.Quit
Set IE = Nothing
End Sub
Sub WaitHalfSec()
Dim t As Single
t = Timer + 1 / 2
Do Until t < Timer: DoEvents: Loop
End Sub
只要我不费劲去寻找内部文本,我就能够找到并存储该行。我该如何返回这条线的日期?
感谢任何帮助!
最佳答案
试试这个:
ReturnValue = IE.document.getElementsByClassName("snapshotController_date.dest")(0).innerText
尽管类名在您检查时似乎有一个空格,但如果您在 DOM 资源管理器中查看,它会显示一个句点。而且它是类名,而不是 ID,因此您需要使用 getElementsByClassName()
方法并使用它返回的 HTMLCollection 对象。
关于html - 我该如何提取这段文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37147209/