Solved

How do I extract the Title of a web page

Posted on 2014-09-12
4
153 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
  • 2
4 Comments
 
LVL 48

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 500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now