【问题标题】:Import Java Script object using VBA使用 VBA 导入 Javascript 对象
【发布时间】:2014-01-08 06:21:47
【问题描述】:

我正在尝试使用 VBA 从 JavaScript 命令中抓取输出。

不幸的是,我有点不知所措。我试过.getElementsByTagName("script")(4).innertext,,但我得到的只是[object]

请参阅下面的 HTML。我正在尝试提取数据数组的。任何帮助将不胜感激

干杯

    <script type="text/javascript">
      var _chartit_hco_array = [
    {
        "series": [
            {
                "stacking": false,
                "data": [
                    4006,
                    34940.1034,
                    61062.5161,
                    95107.6333,
                    167971.8,
                    218549.129,
                    272389.2143,
                    288584.7097,
                    317959.5
                ],
                "type": "column",
                "name": "Dau"
            }
        ],
        "yAxis": [
            {
                "title": {
                    "text": "Daily Active Users (DAU)"
                }
            }
        ],
        "chart": {
            "renderTo": "dauchart_container"
        },
        "xAxis": [
            {
                "categories": [
                    "May<br>2013",
                    "Jun<br>2013",
                    "Jul<br>2013",
                    "Aug<br>2013",
                    "Sep<br>2013",
                    "Oct<br>2013",
                    "Nov<br>2013",
                    "Dec<br>2013",
                    "Jan<br>2014"
                ],
                "title": {
                    "text": "Date"
                }
            }
        ],
        "title": {
            "text": "Daily Active Users (Monthly avg.)"
        }
    },
    {
        "series": [
            {
                "stacking": false,
                "data": [
                    12456.96,
                    204106.3103,
                    320728.5161,
                    442251.9333,
                    646994.0333,
                    1017031.3226,
                    1232705.2857,
                    1377097.3871,
                    1432762.5
                ],
                "type": "column",
                "name": "Mau",
                "label": {
                    "text": "Light breeze",
                    "style": {
                        "color": "#606060"
                    }
                }
            }
        ],
        "yAxis": [
            {
                "title": {
                    "text": "Monthly Active Users (MAU)"
                }
            }
        ],
        "chart": {
            "renderTo": "mauchart_container"
        },
        "xAxis": [
            {
                "categories": [
                    "May<br>2013",
                    "Jun<br>2013",
                    "Jul<br>2013",
                    "Aug<br>2013",
                    "Sep<br>2013",
                    "Oct<br>2013",
                    "Nov<br>2013",
                    "Dec<br>2013",
                    "Jan<br>2014"
                ],
                "title": {
                    "text": "Date"
                }
            }
        ],
        "title": {
            "text": "Monthly Active Users (Monthly avg.)"
        }
    },
    {
        "series": [
            {
                "stacking": false,
                "data": [
                    36.904,
                    18.963103,
                    18.939677,
                    21.466333,
                    25.936,
                    21.515806,
                    22.113929,
                    20.959032,
                    22.19
                ],
                "type": "column",
                "name": "Dau2Mau Percent"
            }
        ],
        "yAxis": [
            {
                "title": {
                    "text": "Daily / Monthly Active Users (DAU/MAU)"
                }
            }
        ],
        "chart": {
            "renderTo": "dau2mauchart_container"
        },
        "xAxis": [
            {
                "categories": [
                    "May<br>2013",
                    "Jun<br>2013",
                    "Jul<br>2013",
                    "Aug<br>2013",
                    "Sep<br>2013",
                    "Oct<br>2013",
                    "Nov<br>2013",
                    "Dec<br>2013",
                    "Jan<br>2014"
                ],
                "title": {
                    "text": "Date"
                }
            }
        ],
        "title": {
            "text": "DAU as percentage of MAU (Monthly avg.)"
        }
    },
    {
        "series": [
            {
                "stacking": false,
                "data": [
                    11057.24,
                    104310.5862,
                    153653.3226,
                    222996.8667,
                    392113.7,
                    546472.0645,
                    674174.0714,
                    710372.6774,
                    771079.5
                ],
                "type": "column",
                "name": "Wau"
            }
        ],
        "yAxis": [
            {
                "title": {
                    "text": "Weekly Active Users (WAU)"
                }
            }
        ],
        "chart": {
            "renderTo": "wauchart_container"
        },
        "xAxis": [
            {
                "categories": [
                    "May<br>2013",
                    "Jun<br>2013",
                    "Jul<br>2013",
                    "Aug<br>2013",
                    "Sep<br>2013",
                    "Oct<br>2013",
                    "Nov<br>2013",
                    "Dec<br>2013",
                    "Jan<br>2014"
                ],
                "title": {
                    "text": "Date"
                }
            }
        ],
        "title": {
            "text": "Weekly Active Users (Monthly avg.)"
        }
    }
];</script>

【问题讨论】:

  • 你能控制html吗?如果是这样,在 jscript 中转换为 CSV 并将其导入 VBA 会容易得多...

标签: javascript html excel scrape vba


【解决方案1】:

你几乎是对的,你必须这样做:

document.getElementsByTagName("script")(4).innerText;   //Check the uppercase T in innerText

(如果返回空字符串,则说明该脚本来自其他域,如果是则无法获取)。

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 2022-01-24
    • 2019-04-03
    • 2018-12-22
    • 1970-01-01
    相关资源
    最近更新 更多