Extract Specific Data from Web into Excel Using Excel VB



  • Hi All,
    I need help on the way to get specific data from a web site in to excel using excel VB.

    1. Here is the HTML code of the web site.
    
     <div id="objects_container">
           <  div id="objects_container" data-sigil="search-results">
                <  div class="_4g33 _52we _5ca3 _5ca1 _ydx">
                  <  div class="_4g34 _195r _5cwg">
                    <  a class="_54k8 _5c9u _5caa" href=
                    "/search/people/?ssid=anotherNumber&amp;search_source=filter&amp;refid=46&amp;q=somenumber&amp;tsid&amp;o=274"
                    role="button" data-sigil="touchable"><  span class="_55sr">Orang<  /span><  /a>
                  <  /div>
                  <  div class="_4g34 _195r _5cwg">
                    <  a class="_54k8 _5c9u _5caa" href=
                    "/search/pages/?ssid=anotherNumber&amp;search_source=filter&amp;refid=46&amp;q=somenumber&amp;tsid"
                    role="button" data-sigil="touchable"><  span class=
                    "_55sr">Halaman<  /span><  /a>
                  <  /div>
                  <  div class="_4g34 _195r _5cwg">
                    <  a class="_54k8 _5c9u _5caa" href=
                    "/search/events/?ssid=anotherNumber&amp;search_source=filter&amp;refid=46&amp;q=somenumber&amp;tsid"
                    role="button" data-sigil="touchable"><  span class="_55sr">Acara<  /span><  /a>
                  <  /div>
                  <  div class="_4g34 _195r _5cwg">
                    <  a class="_54k8 _5c9u _5caa" href=
                    "/search/groups/?ssid=anotherNumber&amp;search_source=filter&amp;refid=46&amp;q=somenumber&amp;tsid"
                    role="button" data-sigil="touchable"><  span class="_55sr">Grup<  /span><  /a>
                  <  /div>
                <  /div>
                <  div>
                  <  div>
                    <  div class="item itemWithAction acw" onclick=
                    "require('MTouchPPSLog').logClick(&quot;result_click&quot;, &quot;id_Number&quot;, 0, 2048);"
                    data-sigil="undoable-action marea">
                      <  a class="touchable primary" href=
                      "[COLOR="#FF0000"][B][SIZE=5]/profile.php?id=id_Number&amp;refid=46&amp;fref=search[/SIZE][/B][/COLOR]"
                      data-sigil="touchable"><  /a>
    
                      <  div class="primarywrap">
                        <  div class="image"><  /div>
                        <  div class="content">
                          <  div class="title _1i1q mfsl fcb">
                            <  strong>[B][COLOR="#FF0000"][SIZE=5]One Name[/SIZE][/COLOR][/B]<  /strong>
                          <  /div>
                          <  div class="subtitle fcg">
                            <  div class="_4z0-" id="u_0_2" data-sigil=
                            "m-friend-request-highlight-notice">
                              <  div class="notice" style="display: none;" data-sigil=
                              "m-add-friend-request-sent">
                                Permintaan terkirim
                              <  /div>
                              <  div class="notice ellipsis" data-sigil=
                              "m-add-friend-source-replaceable"><  /div>
                              <  div style="display: none;" class="notice" data-sigil=
                              "m-friend-request-canceled">
                                Permintaan dibatalkan
                              <  /div>
                            <  /div>
                          <  /div>
                        <  /div>
                      <  /div>
    
    
    1. My Target is Get the following Item
    2. "One Name" (Mark in italic and Bold) and put it on excel on range ("B1")
    3. the link href="/profile.php?id=id_Number&refid=46&fref=search" (Mark in italic and Bold) and put it on range("C1")

    Below is my macro (and giving me something else other then what I want)

    Sub PullDataFromWeb()
            Dim ie As New InternetExplorer
            Dim doc As HTMLDocument
            
            ie.Visible = True
        
            ie.navigate "Url link here"
        
            Do
                DoEvents
            Loop Until ie.readyState = 4
            
            Set doc = ie.document
            
           ***strTitle = doc.getElementById("objects_container").getElementsByTagName("Strong")(0).innerText***
            'PLEASE CORRECT ME ON THIS PART
            'I TRY USING getElementByClassName but come up with error "Object doesn't support this property or method"
            MsgBox strTitle
            
            'I haven't assigned it to range("B1") just show it in message box first and if correct then I will do so.
           
    End Sub
    

    the result is
    ![0_1498557756015_upload-8ded3071-d5cd-4bc2-b61e-3e3d487861be](Uploading 100%)

    Thank you in advance for sort this things out.

    Regards,
    Benny


  • administrators

    @bennyys It's hard to debug without looking at the actual URL. Above posted HTML is also not in the right format.


Log in to reply
 

Looks like your connection to Codingislove Forum was lost, please wait while we try to reconnect.