我想检索HTML网页中内联的Javascript变量的内容。


我可以通过它的位置检索< script>
节点,但我想知道是否有更灵活的方法可以看在变量名本身 - 节点位置可能会改变。
例如,页面URL是 https://poloniex.com/marginTrading ,我正在寻找变量 markets_currencies
的内容,其中包含可以归档的所有货币。此信息无法通过API获取。
< script type =“text / javascript”>
 var loggedIn = false;&# xA; var dark = false;
 var mobile = false;
 var mobileDetected = false;
 var usid = false;
 var markets = {};
 var markets_currencies = {“bySymbol”:{“1CR”:{“id”:1,“symbol”:“1CR”,“name”:“1CRedit”,“canLend”:0},“ABY”:{“id”: 2,“symbol”:“ABY”,“name”:“ArtByte”,“canLend”:0} ...}};
 if(window.top!== window.self)window.top。 location.replace(window.self.location.href);
< / script>



 到现在为止我检索了这样的网页:


 html< - getURL(“https://poloniex.com/marginTrading”,followlocation = TRUE)
 doc = htmlParse(html,asText = TRUE)
 plaintext< - xpathSApply(doc,“// script”,xmlValue)
 cat(paste(plaintext [[5]],collapse =“\ n”))



 但是直到更进一步我意识到存储变量的< script>
节点位置可能会发生变化,这不是一个灵活的解决方案。实现这一目标的最佳方法是什么?
谢谢,