Parsing HTML title into Excel

Majawat

New Member
Joined
Jun 14, 2011
Messages
49
I appologize for my post at http://www.mrexcel.com/forum/showthread.php?t=557472. I accidently used a TITLE html tag in the post... lesson learned! (if I can delete it, I will,

After a quick search through the forums and google, I can't seem to find the answer to this question.

Basically, I'm trying to pull the webpage title from this website http://beeradvocate.com/beer/profile/140. Really all I want is the "Sierra Nevada Brewing Co.", but I'll gladly take the "Sierra Nevada Brewing Co. - Chico, CA - Beers - BeerAdvocate" if it is easier since that is contained in the TITLE tag of the HTML. This string will then be placed in the currently selected cell.

If it helps, I'm already opening an IE object and parsing the table on the page as it is.

Suggestions? Help?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Can't you just search for the TITLE element of the HTML document of the page?

You don't say exactly say how you are opening IE etc but this worked for me.
Code:
doc.getElementsbytagname("TITLE")(0).InnerText
Where doc was a reference to IE.document.
 
Upvote 0
Can't you just search for the TITLE element of the HTML document of the page?

You don't say exactly say how you are opening IE etc but this worked for me.
Code:
doc.getElementsbytagname("TITLE")(0).InnerText
Where doc was a reference to IE.document.

This is the code I'm using to open the IE object:

Code:
dim objIE as Object
 
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
    .AddressBar = False
    .StatusBar = False
    .MenuBar = False
    .Toolbar = 0
    .Visible = False
    .Navigate strURL
End With
While objIE.Busy
Wend
While objIE.Document.ReadyState <> "complete"
Wend

I had tried changing your code to this with no such luck:

Code:
objIE.getElementsbytagname("TITLE")(0).InnerText
with an error of Object doesn't support this property or method.

And thank you for your quick response!
 
Upvote 0
Sorry I created a reference to the document.
Code:
Set doc = objIE.document
 
doc.getElementsbytagname("TITLE")(0).InnerText
 
Upvote 0
BTW, if you need to post HTML tags in your post, there is a way to show them.

Just use &#xx; tags.

i.e.

&#60;TITLE&#62; = <TITLE>
 
Last edited:
Upvote 0
Norie, thank you for your help, however I still didn't get that code to work. Nor do I understand how VBA objects work quite yet.

However, I did end up getting it to work myself with this piece of code:
Code:
dim varTitles, varTitle
...
 
Set varTitles = objIE.document.all.tags("TITLE")
 
For Each varTitle In varTitles
    ActiveSheet.Cells(lngRow, 2) = Trim(Left(varTitle.innertext, Application.WorksheetFunction.Find("-", varTitle.innertext) - 2))
Next varTitle
This not only grabs it, but it also grabs just the part I need.

HOTPEPPER, thank you, I'll keep that in mind in the future!
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,219
Members
452,895
Latest member
BILLING GUY

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