Extract Specific Data from Web into Excel Using Excel VB

bennyys

New Member
Joined
Jun 22, 2017
Messages
17
Hi All,
I need help on the way to get specific data from a web site in to excel using excel VB.


Here is the HTML code of the web site.
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"> [COLOR=#FF0000][SIZE=5][B]<  div id="objects_container">[/B][/SIZE][/COLOR]
          [COLOR=#FF0000][SIZE=5][B]<  div id="objects_container" data-sigil="search-results">[/B][/SIZE][/COLOR]
            <  div class="_4g33 _52we _5ca3 _5ca1 _ydx">
              <  div class="_4g34 _195r _5cwg">
                <  a class="_54k8 _5c9u _5caa" href=
                "/search/people/?ssid=anotherNumber&search_source=filter&refid=46&q=somenumber&tsid&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&search_source=filter&refid=46&q=somenumber&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&search_source=filter&refid=46&q=somenumber&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&search_source=filter&refid=46&q=somenumber&tsid"
                role="button" data-sigil="touchable"><  span class="_55sr">Grup<  /span><  /a>
              <  /div>
            <  /div>

            <  div>
              <  div>
                <  div class="item itemWithAction acw" *******=
                "require('MTouchPPSLog').logClick("result_click", "id_Number", 0, 2048);"
                data-sigil="undoable-action marea">
                  <  a class="touchable primary" href=
                  "[COLOR=#FF0000][B][SIZE=5]/profile.php?id=id_Number&refid=46&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></code>

My Target is Get the following Item
1. "One Name" (Mark in red and bold) and put it on excel on range ("B1")
2. the link href="/profile.php?id=id_Number&refid=46&fref=search" (Mark in red and bold) and put it on range("C1")
Below is my macro (and giving me something else other then what I want)

Code:
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


Thank you in advance for sort this things out.


Regards,
Benny
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
im no expert on HTML but isn't one name in the class "content" whereas you are trying to get it from the id objects_container?
 
Upvote 0
BarryL ,
1. im no expert on HTML but isn't one name in the class "content" (answer: Yes it is in class "content" BUT you can see on my next note in the 'I TRY USING getElementByClassName but come up with error "Object doesn't support this property or method". I hope it is clear for you.

2. whereas you are trying to get it from the id objects_container? (answer: please look at the top of the code I mark it with red and bold. That is the closest id to "One Name".)
 
Upvote 0
is the access to this website restricted? be much easier to test if we had the website
 
Upvote 0
1. is the access to this website restricted? (answer: No restriction at all)
2. be much easier to test if we had the website (answer: open your facebook, go to search page and type phone number of your friend. if found some then copy FB user name (This one will be the the "One Name" on my code above and paste it to excel column B1. Next step Copy link address (this one will be "
the link href="/profile.php?id=id_Number&refid=46&fref=search" and paste it to column C1. Let me know if you get any luck
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,706
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top