?
Solved

How do I extract the Title of a web page

Posted on 2014-09-12
4
Medium Priority
?
172 Views
Last Modified: 2014-09-13
I am using Excel VBA to scrape a page.
Everything is work, but I can't get the title.
HTMLDoc.Title is not returning anything, but HTMLDoc.body returns the text of the body.
0
Comment
Question by:rrhandle8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40319943
Hi,

pls try

Sub ImportEE()

Dim ie As InternetExplorer
Dim html As HTMLDocument

Set ie = New InternetExplorer
ie.Visible = False
ie.navigate "http://www.experts-exchange.com/"


Do While ie.readyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Set html = ie.document

MsgBox html.Title

Set ie = Nothing

End Sub

Open in new window

Regards
0
 

Author Comment

by:rrhandle8
ID: 40319998
Here is the code I am using:

   Dim HTMLDoc As New HTMLDocument
    Dim oHttp As MSXML2.XMLHTTP
    Dim sHTML As String
    Dim AnchorLinks As Object
    Dim TDelements As Object
    Dim TDelement As Object
    Dim AnchorLink As Object

    On Error Resume Next
    Set oHttp = New MSXML2.XMLHTTP
    If Err.Number <> 0 Then
        Set oHttp = CreateObject("MSXML.XMLHTTPRequest")
        MsgBox "Error 0 has occured while creating a MSXML.XMLHTTPRequest object"
    End If
    On Error GoTo 0
    If oHttp Is Nothing Then
        MsgBox "For some reason I wasn't able to make a MSXML2.XMLHTTP object"
        Exit Sub
    End If

    'Open the URL in browser object
    oHttp.Open "GET", URL, False
    oHttp.send
    sHTML = oHttp.responseText

    'Debug.Print oHttp.responseText

    HTMLDoc.body.innerHTML = oHttp.responseText
HTMLDoc.Title
0
 

Author Comment

by:rrhandle8
ID: 40320084
Any ideas?
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 2000 total points
ID: 40320177
Following your code, you can extract the title from the responseText:

     HTMLDoc.Title = Mid(oHttp.responseText, InStr(1, oHttp.responseText, "<Title>", vbTextCompare) + 7, _
                    InStr(1, oHttp.responseText, "</Title>", vbTextCompare) - _
                    InStr(1, oHttp.responseText, "<Title>", vbTextCompare) - 7)

Open in new window


Regards,
-Glenn
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question