Jump to content

Scraping data from a website HTML source (with VB example)


Raex

Recommended Posts

Hi, I'm trying to retrieve/scrape some information from a website using the class name and the tag name.

Below is the example in VB: 

        Dim htmL_cat As HTMLDocument
        Dim objTableL_cat As Object, objDatL_cat As Object, objItemL_cat As Object, objKeyL_cat As Object
        Dim intRowL_cat As Long

        Set htmL_cat = New HTMLDocument

        With CreateObject("MSXML2.XMLHTTP")
            .Open "GET", "http://www.lelong.com.my/Auc/List/BrowseAll.asp", False
            .send
            htmL_cat.body.innerHTML = .responseText
        End With

        With htmL_cat
            Set objTableL_cat = .getElementsByClassName("CatLevel1")   'Find elements with class name first
            For Each objDatL_cat In objTableL_cat
                Set objKeyL_cat = objDatL_cat.getElementsByTagName("a")    'Next, find elements with tag name
                For Each objItemL_cat In objKeyL_cat
                    Sheets("Analytics").Range("E6").Offset(intRowL_cat, 0) = objItemL_cat.innerText
                    intRowL_cat = intRowL_cat + 1
                Next
            Next
        End With

        Set htmL_cat = Nothing
        Set objTableL_cat = Nothing
        Set objKeyL_cat = Nothing

How do I do the same using PHP? Thanks.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.