0

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 Multi Bedspread - Double"
  2. "This stunning ivory bedspread has been specially designed to sit with the Helena bedroom range. It features a subtle floral design with a diamond shaped quilted finish. The bedspread is padded so can be used as a lightweight quilt in the summer or as an extra layer in the winter. Polyester. Size L260, W240cm. Suitable for a double bed. Machine washable at 30°C. Suitable for tumble drying. EAN: 5055184924746.
  3. Product Code 116/4196"

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.

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

3

This seems to be not too difficult. You can use Firefox to take a look at the page structure (right-click somewhere and click inspect element, and go on from there...)

Here is a simple sample code:

Sub test()
    Dim ie As InternetExplorer
    Dim x

    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://www.argos.co.uk/static/Product/partNumber/1164196.htm"
    While ie.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Wend

    Set x = ie.Document.getElementById("pdpProduct").getElementsByTagName("h1")(0)
    MsgBox Trim(x.innerText)

    Set x = ie.Document.getElementById("genericESpot_pdp_proddesc2colleft").getElementsByTagName("div")(0)
    MsgBox x.innerText

    Set x = ie.Document.getElementById("pdpProduct").getElementsByTagName("span")(0).getElementsByTagName("span")(2)
    MsgBox x.innerText

    ie.Quit
End Sub

(I have a reference in Excel to Microsoft Internet Controls, I don't know if that is there by default, if not you have to set it first to run this code).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.