需要帮助用 excel vba 抓取 [英] need help scraping with excel vba

查看:39
本文介绍了需要帮助用 excel vba 抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 <<<HERE>>> 在这种情况下是:

I need to scrape Title, product description and Product code and save it into worksheet from <<<HERE>>> in this case those are :

  1. Catherine Lansfield Helena 多床罩 - 双人"
  2. 这款令人惊艳的象牙色床罩专为搭配 Helena 卧室系列而设计.它采用微妙的花卉设计和菱形绗缝饰面.床罩带有衬垫,因此可在夏季用作轻质被子或作为冬天多加一层.聚酯纤维.尺寸 L260,W240cm.适合一张双人床.可在 30°C 下机洗.适合滚筒烘干.EAN:5055184924746.
  3. 产品代码 116/4196"

我尝试了不同的方法,但最终没有一个对我有好处.对于 Mid 和 InStr 函数结果为 none,可能是我的代码错误.对不起,我没有给出任何代码,因为我已经把它搞砸了很多次,但没有结果.我试图用 GetDatafromPage 刮洞页面.它运作良好,但对于不同的产品页面,随着元素数量从页面到页面的变化,输出会转到不同的行.此外,不可能只抓取选定的元素.所以从定义的单元格中获取价值是没有意义的.

I have tried different methods and none was good for me in the end. For Mid and InStr functions result was none, it could be that my code was wrong. Sorry i do not give any code because i had already messed it up many times and have had no result. I have tried to scrape hole page with GetDatafromPage. It works well, but for different product pages the output goes to different rows as ammount of elements changes from page to page. Also it`s not possible to scrape only chosen elements. So it is pointless to get value from defined cells.

推荐答案

另一个不使用 InternetExplorer 对象的选项是 xmlhttp 对象.这是与 kekusemau 类似的示例,但使用 xmlhttp 对象来请求页面.然后我从 html 文件中的 xmlhttp 对象加载 responseText.

Another option instead of using the InternetExplorer object is the xmlhttp object. Here is a similar example to kekusemau but instead using xmlhttp object to request the page. I am then loading the responseText from the xmlhttp object in the html file.

Sub test()
    Dim xml As Object
    Set xml = CreateObject("MSXML2.XMLHTTP")
    xml.Open "Get", "http://www.argos.co.uk/static/Product/partNumber/1164196.htm", False
    xml.send

    Dim doc As Object
    Set doc = CreateObject("htmlfile")
    doc.body.innerhtml = xml.responsetext

    Dim name
    Set name = doc.getElementById("pdpProduct").getElementsByTagName("h1")(0)
    MsgBox name.innerText

    Dim desc
    Set desc = doc.getElementById("genericESpot_pdp_proddesc2colleft").getElementsByTagName("div")(0)
    MsgBox desc.innerText

    Dim id
    Set id = doc.getElementById("pdpProduct").getElementsByTagName("span")(0).getElementsByTagName("span")(2)
    MsgBox id.innerText
End Sub

这篇关于需要帮助用 excel vba 抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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