Excel VBA中的HTML页面标题

时间:2011-10-02 08:26:53

标签: html excel vba excel-vba internet-explorer

给定一个网址,如何在Excel中获取VBA中html页面的标题?

例如假设我有三个网址:

现在我需要在另一列中获取这些html页面的标题。我该怎么做?

3 个答案:

答案 0 :(得分:6)

Remou的答案对我非常有帮助,但它引起了一个问题:它没有关闭Internet Explorer进程,所以因为我需要运行这几十次,所以我最终打开了太多IE,而我的计算机无法运行处理这件事。

所以只需添加

wb.Quit

一切都会好的。

这是适用于我的代码:

Function GetTitleFromURL(sURL As String)
Dim wb As Object
Dim doc As Object

Set wb = CreateObject("InternetExplorer.Application")

wb.Navigate sURL

While wb.Busy
    DoEvents
Wend

GetTitleFromURL = wb.Document.Title

wb.Quit

Set wb = Nothing
End Function

答案 1 :(得分:5)

我不确定你的名字是什么意思,但这是一个想法:

Dim wb As Object
Dim doc As Object
Dim sURL As String

Set wb = CreateObject("InternetExplorer.Application")

sURL = "http://lessthandot.com"

wb.Navigate sURL

While wb.Busy
    DoEvents
Wend

''HTML Document
Set doc = wb.document

''Title
Debug.Print doc.Title

Set wb = Nothing

答案 2 :(得分:0)

如果你使用硒:

Sub Get_Title()
Dim driver As New WebDriver
debug.print driver.Title
End Sub