我将如何提取此文本
How would I pull this text
我正在查看此网页 -> https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=671299425542&locale=en_US&cntry_code=us
我想 return 交货日期星期四 3/31/2016 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
只要我不厌倦进入内部文本,我就能够找到并存储它看起来的行。我如何在这条线上 returning 日期?
< div class = "snapshotController_date.dest" > 2016 年 3 月 31 日星期四 12:16 下午 < / div >
感谢任何帮助!
试试这个:
ReturnValue = IE.document.getElementsByClassName("snapshotController_date.dest")(0).innerText
尽管 class 名称在您检查时似乎有一个 space,但如果您在 DOM 资源管理器中查看,它会有一个句点。它也是 class 名称,而不是 ID,因此您需要使用 getElementsByClassName()
方法并使用它 returns.
的 HTMLCollection 对象
我能够让它工作。只是为任何需要它的人提供答案。
Public Sub FedExTrackingWorking()
Dim ie As Object
Dim ProURL As String
Dim iCounter As Integer
Dim htmlColl As MSHTML.IHTMLElementCollection
Dim htmlInput As MSHTML.HTMLInputElement
Dim RowCount As Integer
RowCount = 0
Set ie = CreateObject("InternetExplorer.application")
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 htmlColl = ie.document.getElementsByTagName("div")
For Each htmlInput In htmlColl
If htmlInput.className = "snapshotController_date dest" Then
ActiveCell.Offset(RowCount).Value = htmlInput.innerText
Exit For
End If
Next htmlInput
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
我正在查看此网页 -> https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=671299425542&locale=en_US&cntry_code=us
我想 return 交货日期星期四 3/31/2016 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
只要我不厌倦进入内部文本,我就能够找到并存储它看起来的行。我如何在这条线上 returning 日期?
< div class = "snapshotController_date.dest" > 2016 年 3 月 31 日星期四 12:16 下午 < / div >
感谢任何帮助!
试试这个:
ReturnValue = IE.document.getElementsByClassName("snapshotController_date.dest")(0).innerText
尽管 class 名称在您检查时似乎有一个 space,但如果您在 DOM 资源管理器中查看,它会有一个句点。它也是 class 名称,而不是 ID,因此您需要使用 getElementsByClassName()
方法并使用它 returns.
我能够让它工作。只是为任何需要它的人提供答案。
Public Sub FedExTrackingWorking()
Dim ie As Object
Dim ProURL As String
Dim iCounter As Integer
Dim htmlColl As MSHTML.IHTMLElementCollection
Dim htmlInput As MSHTML.HTMLInputElement
Dim RowCount As Integer
RowCount = 0
Set ie = CreateObject("InternetExplorer.application")
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 htmlColl = ie.document.getElementsByTagName("div")
For Each htmlInput In htmlColl
If htmlInput.className = "snapshotController_date dest" Then
ActiveCell.Offset(RowCount).Value = htmlInput.innerText
Exit For
End If
Next htmlInput
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