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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.