Solved

How do I extract the Title of a web page

Posted on 2014-09-12
4
163 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 51

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

738 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