通过excel从网站检索具体数据 [英] Retrieving specific data from website through excel

查看:121
本文介绍了通过excel从网站检索具体数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与以下现有示例类似的内容:
参考问题

I am trying to do something very similar to the below existing example: reference problem

除了一个小例外,我只需要拉这个评分评论数量在Excel中列出两个单独的单元格。

With one small exception, I need to pull only the rating and # of reviews for this listing into 2 separate cells in Excel.

如何在不拉扯整个网站数据的情况下执行此操作?看来我需要调用一个特定的html标签或使用命令来做到这一点,但我不知道是什么。

How would I do this in a way without pulling the entire site's data? It seems I need to call a specific html tag or use a command to do this, but I don't know what it is.

请帮助!

推荐答案

此代码将检索您请求的两条信息,并将其放在活动表单上

This code will retrieve the two pieces of information you requested and place them on the activesheet

Sub test()
    my_url = "http://www.yelp.com/biz/if-boutique-new-york"
    Set html_doc = CreateObject("htmlfile")
    Set xml_obj = CreateObject("MSXML2.XMLHTTP")

    xml_obj.Open "GET", my_url, False
    xml_obj.send
    html_doc.body.innerhtml = xml_obj.responseText
    Set xml_obj = Nothing

    Set Results = html_doc.body.getElementsByTagName("i")
    For Each itm In Results
        If InStr(1, itm.outerhtml, "star-img", vbTextCompare) > 0 Then
            numb_stars = itm.getAttribute("title")
            Exit For
        Else
        End If
    Next

    Set Results = html_doc.body.getElementsByTagName("span")
    For Each itm In Results
        If InStr(1, itm.outerhtml, "reviewCount", vbTextCompare) > 0 Then
            numb_rev = itm.innertext
            Exit For
        Else
        End If
    Next

    ActiveCell = numb_stars
    ActiveCell.Offset(1, 0) = numb_rev
End Sub

这篇关于通过excel从网站检索具体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆