【发布时间】:2018-06-13 02:59:50
【问题描述】:
我试图了解为什么我的参考资料不能很好地抓取这些数据。
这里以网站为例:
http://quote.morningstar.ca/Quicktakes/Financials/is.aspx?t=GNTX®ion=USA&culture=en-CA&ops=clear
并作为目标:
<div id="data_i6" class="rf_crow"><div id="Y_1" class="pos column6Width_noChart116px" style="overflow:hidden;white-space: nowrap;" rawvalue="741131269">741</div><div id="Y_2" class="pos column6Width_noChart116px" style="overflow:hidden;white-space: nowrap;" rawvalue="836611464">837</div><div id="Y_3" class="pos column6Width_noChart116px" style="overflow:hidden;white-space: nowrap;" rawvalue="939841654">940</div><div id="Y_4" class="pos column6Width_noChart116px" style="overflow:hidden;white-space: nowrap;" rawvalue="1010472512">1,010</div><div id="Y_5" class="pos column6Width_noChart116px" style="overflow:hidden;white-space: nowrap;" rawvalue="1100344312">1,100</div><div id="Y_6" class="pos column6Width_noChart116px" style="overflow:hidden;white-space: nowrap;" rawvalue="1115401551">1,115</div></div>
我需要提取的是 rawvalue="741131269" 中的实际值,以下是我到目前为止所做的工作。
'Cells(1, 1) = Document.getElementsByClassName("rf_crow")'returns the rows of data into one cell
'Cells(1, 1) = Document.getElementById("Y_1").innerText 'returns the text for the year
'Cells(1, 1) = Document.getElementById("data_i1").innerText 'returns to first row of data
我知道上面没有返回我想要的,因为注释告诉你它提取到 Excel 中的内容。子元素似乎不像在我构建的其他宏中那样工作。我认为这样的事情会起作用:
Cells(1, 1) = Document.getElementById("Y_1").getAttribute("rawvalue")
但这不起作用,我也试过了:
Cells(1, 1) = Document.getElementById("data_i6").getElementById("Y_1").innertext
这也不行。
【问题讨论】:
标签: vba excel web-scraping