Stuck on a div code

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,066
Office Version
  1. 2016
Platform
  1. Windows
I have this code that takes data from a html element by Id, the ID in this case is "MainBody_lblBankDetails" It then displays it in a message box.

Code:
 Private Sub CommandButton7_Click()
 With CreateObject("InternetExplorer.Application")
      .navigate "http://swiftcode.a1feeds.com/Swift_Code.aspx?Swift_Code=ATBRCA6EXXX"
        Do
           DoEvents
        Loop Until .readyState = 4
         
        MsgBox .document.getElementById("[B]MainBody_lblBankDetails[/B]").innerText
    End With
End Sub

This is the HTML that it takes it from

HTML:
<div class="BlueBox1">
                <span id="MainBody_lblBankDetails"><b>Bank : </b>ALBERTA TREASURY BRANCHES<br /><b>City : </b>EDMONTON<br /><b>SWIFT Code : </b>ATBRCA6EXXX</span>
            </div>

What i need is a code like this but works a bit different.

1) No message box, data is displayed in sheet1 column A
2) The result will show in the next blank rows as i will be using a list of url from sheet2, (I already haev the code to get urls from sheet2)
3) The above code searchs an element via ID in a div. My problem is there is no element ID just a div, the div class in this case is "bio"

HTML:
 <div class="bio">
          More Information contact : XXXXX XXXXX XXXXX Social : https://www.facebook.com/
        </div>
T

he data is only text. I have tried to change the code but I am having no luck.

Can someone help please
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I sorted most of the code its like this now still stuck on a few things, main one being that it pastes the result in Sheet1 below next empty row as show in red, I get error message here. Object does not support this property or method

Code:
Private Sub CommandButton8_Click()
Dim IE As New InternetExplorer
IE.navigate " [B]YOUR URL[/B]"
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Application.Wait (Now() + TimeValue("00:00:016")) ' For internal page refresh or loading
Dim doc As HTMLDocument 'variable for document or data which need to be extracted out of webpage
Set doc = IE.document
Dim dd As Variant
dd = doc.getElementsByClassName("[B]bio[/B] ")(0).innerText

'MsgBox dd

[COLOR=#ff0000]Sheet1.Range("A1" & EndxlDown).Offset(1, 0).Paste[/COLOR]

'Close IE Browser
      IE.Quit
     Set IE = Nothing

End Sub
 
Upvote 0
Change the red line:

Code:
Sheet1.Cells(Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row + 1, "A").Value = dd

WBD
 
Upvote 0
Thanks WideBoyDixon, this has sorted it out
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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