I am trying to extract the 3/14/2017 from the following HTML code:
我想从以下HTML代码中提取3/14/2017:
<div class="divListTableBodyCell" id="tdColumnPostDateCell">
<table class="tblListTableBodyCell">
<tr>
<td>
<div class="divListTableBodyLabel">3/14/2017</div>
I am using Excel VBA to do so and have the following code to try to test the information that I am pulling:
我正在使用Excel VBA这样做,并使用以下代码来尝试测试我提取的信息:
Sub CC()
Dim ie As Object
marker = 0
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next
my_url = objShell.Windows(x).document.Location
my_title = objShell.Windows(x).document.Title
If my_title Like "Main" & "*" Then
Set ie = objShell.Windows(x)
marker = 1
Exit For
Else
End If
Next
extract1 = ie.document.getElementsByClassName("divListTableBodyLabel")(3).innerText
MsgBox extract1
There are multiple instances of divListTableBodyLabel on the page with various dates, so I am just seeing if I can get any of them to appear and then I can worry about getting the exact one I want. I have tried all of the id's or class names above and nothing returns?
页面上有多个divListTableBodyLabel实例,各种日期,所以我只是看看我是否可以让它们中的任何一个出现,然后我可以担心得到我想要的那个。我已经尝试过上面的所有id或类名,没有任何回报?
1 个解决方案
#1
0
Someone here gave me the following code to set an IE object, and it works fantastically.
这里有人给了我以下代码来设置一个IE对象,它的工作非常有用。
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim RetVal As Object
Set RetVal = Nothing
Set objShell = CreateObject("shell.application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sURL = ""
On Error Resume Next
'check the URL and if it's the one you want then
'assign it to the return value and exit the loop
sURL = o.document.location
On Error GoTo 0
If sURL Like "*" & sLocation & "*" Then
Set RetVal = o
Exit For
End If
Next o
Set GetIE = RetVal
End Function
So just Set IE = GetIE("www.google.com")
and you are good to go. See if this helps any.
所以只需设置IE = GetIE(“www.google.com”)就可以了。看看这是否有帮助。
#1
0
Someone here gave me the following code to set an IE object, and it works fantastically.
这里有人给了我以下代码来设置一个IE对象,它的工作非常有用。
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim RetVal As Object
Set RetVal = Nothing
Set objShell = CreateObject("shell.application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sURL = ""
On Error Resume Next
'check the URL and if it's the one you want then
'assign it to the return value and exit the loop
sURL = o.document.location
On Error GoTo 0
If sURL Like "*" & sLocation & "*" Then
Set RetVal = o
Exit For
End If
Next o
Set GetIE = RetVal
End Function
So just Set IE = GetIE("www.google.com")
and you are good to go. See if this helps any.
所以只需设置IE = GetIE(“www.google.com”)就可以了。看看这是否有帮助。