[英]VBA XMLHTTP request doesn't capture dynamic HTML response
I am trying to get a specific dynamic figure from a webpage to excel, I managed to gather all the website get response into a "all" variable which I am supposed to parse to extract my numbers, except for when I check the string variable I can see everything but the required dynamic figure: .) "the attached phot shows the dynamic figure at the very instant was 2,19", any ideas why I am capturing every thing, would be much appreciated, Thanks in advance我正在尝试从网页获取特定的动态图形到 excel,我设法将所有网站获取响应收集到一个“全部”变量中,我应该解析该变量以提取我的数字,除非我检查字符串变量 I可以看到除了所需的动态图之外的所有内容:。)“所附照片显示了瞬间的动态图是 2,19”,任何我捕捉每件事的想法,将不胜感激,在此先感谢
My thoughts: 1.I am guessing is the figures are injected by JavaScript or a server side that might be executing after my XMLHTTP request is processed maybe!我的想法: 1.我猜这些数字是由 JavaScript 或在我的 XMLHTTP 请求处理后可能正在执行的服务器端注入的! if this is the case or else I need your expertise
如果是这种情况,否则我需要你的专业知识
Please see below my code and a screenshot for the figure I would like to capture请在下面查看我的代码和我想要捕获的图的屏幕截图
'Tools>refrences>microsoft xml v3 must be refrenced
Public Function GetWebSource(ByRef URL As String) As String
Dim xml As IXMLHTTPRequest
On Error Resume Next
Set xml = CreateObject("Microsoft.XMLHTTP")
With xml
.Open "GET", URL, False
.send
GetWebSource = .responseText
End With
Set xml = Nothing
End Function
Sub ADAD()
Dim all As Variant
Dim objHTTP As Object
Dim URL As String
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
all = GetWebSource("https://www.tradingview.com/symbols/CRYPTOCAP-ADA.D/")
pos = InStr(all, "tv-symbol-price-quote__value js-symbol-last")
testString = Mid(all, pos, 200)
'I am supposed to see the dynamic figure within the TAG but it is not showing!!
Debug.Print testString
End Sub
@Tim Williams This is a code using selenium (But it seems doesn't do the trick of getting the value) @Tim Williams 这是一个使用 selenium 的代码(但它似乎没有获得价值的诀窍)
Sub Test()
Dim bot As Selenium.PhantomJSDriver
Set bot = New Selenium.PhantomJSDriver
With bot
.Get "https://www.tradingview.com/symbols/CRYPTOCAP-ADA.D/"
.Wait 2000
Debug.Print .FindElementByXPath("//div[@class='tv-symbol-price-quote__value js-symbol-last']").Attribute("outerHTML")
End With
End Sub
It seems using PhantomJS
doesn't work properly, so here's a Chrome version of selenium in VBA似乎使用
PhantomJS
不能正常工作,所以这里是 VBA 中 selenium 的 Chrome 版本
Private bot As Selenium.ChromeDriver
Sub Test()
Set bot = New Selenium.ChromeDriver
With bot
.Start
.Get "https://www.tradingview.com/symbols/CRYPTOCAP-ADA.D/"
Debug.Print .FindElementByXPath("//div[@class='tv-symbol-price-quote__value js-symbol-last']").Text 'Attribute("outerHTML")
.Quit
End With
End Sub
And this is the working python code that my tutor @QHarr provided in comments这是我的导师@QHarr 在评论中提供的工作 python 代码
from selenium import webdriver
d = webdriver.Chrome("D:/Webdrivers/chromedriver.exe")
d.get('https://www.tradingview.com/symbols/CRYPTOCAP-ADA.D/')
d.find_element_by_css_selector('.tv-symbol-price-quote__value.js-symbol-last').text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.