我有一个VBA脚本,多年来我一直在使用这些代码来提取伦敦证券交易所网站上的公司报告日期。他们最近更改了他们的网络查询界面,我一直在尝试修改脚本,但遇到了一些困难。
我从摘要中提取了一部分,URL下方的URL要求提供2019年特定月份的数据,但是请求的字段没有任何数据。该网页的回应是“对不起,我们找不到符合您条件的任何结果。请重试。”我希望找到并检查此文本是否存在,如果为true,则退出循环。
我的脚本首先解析名为“ section”的HTML标签,然后在每个部分中尝试解析名为“ div”的每个HTML标签。文本在“ div”标签之一内。
我可以在“ sction”循环中对代码进行断点处理,尽管我很确定“ div”标记在“ section”标记内,但它没有拾取任何“ div”标记。
我也不确定我的字符串比较是否有效,因为由于内部循环未执行,所以我无法进行检查。
有人可以善良地指出我要去哪里了吗?
非常感谢
GLW
'''
Dim oDom As Object: Set oDom = CreateObject("htmlFile")
Dim tbl As Object
Dim sction As Object
Dim spn As Object
Dim div_txt As Object
Dim TestSplit() As String
Dim innerText As String
Dim htmlEle1 As Object
With CreateObject("msxml2.xmlhttp.6.0")
.Open "GET", "https://www.londonstockexchange.com/news?tab=news-explorer&indices=NMX&headlinetypes=1&headlines=42&period=custom&beforedate=20190731&afterdate=20190701"
.send
oDom.body.innerHtml = .responseText
End With
'check to see if the page is empty
For Each sction In oDom.body.getElementsByTagName("section")
innerText = sction.innerText
For Each htmlEle1 In sction.getElementsByTagName("div")
innerText = htmlEle1
If [innerText = "Sorry, we couldn't find any results for your criteria. Please try again."] Then Exit For
Next htmlEle1
Next sction
这对我有用:
Const NO_HITS As String = "Sorry, we couldn't find any results for your criteria. Please try again."
With CreateObject("msxml2.xmlhttp.6.0")
.Open "GET", "https://www.londonstockexchange.com/news?tab=news-explorer&indices=NMX&headlinetypes=1&headlines=42&period=custom&beforedate=20190731&afterdate=20190701"
.send
If InStr(.responseText, NO_HITS ) > 0 Then
Debug.Print "No results"
Else
Debug.Print "OK"
End If
End With