我需要用vb6搜索youtube api,我在网上能找到的只有其他流行语言的库
目前,我使用以下网址搜索
URL = "http://www.youtube.com/results?search_query=" & TextBox1.Text &
"&suggested_categories=2%2C23%2C25&page=" & pagenum
我必须使用regex解析页面,如果搜索页面中的某些内容发生变化,regex可能会失败
但我更希望我能用api来做这件事,有人能建议一个资源或解决方案
为什么不使用Internet Explorer附带的MSHTML解析网页?您需要添加对"Microsoft HTML对象库"的引用。奇怪的是,您必须实例化一个空的HTMLDocument对象,然后通过在第一个对象上调用一个方法,根据您的URL创建一个新的HTMLDocument。但你必须保留原始对象,否则你会不断收到"权限被拒绝"的错误消息。我仍然将它们都放入UDT中,以确保它们保持在彼此相同的范围内。
Option Explicit
Private Type HtmlDoc
Parent As MSHTML.HTMLDocument
Main As MSHTML.HTMLDocument
End Type
Private Sub Command1_Click()
Dim URL
Dim uHTMLDoc As HtmlDoc
URL = "http://www.youtube.com/results?search_query=" & TextBox1.Text & "&suggested_categories=2%2C23%2C25&page=" & pagenum
' Source Code
GetHTMLDocumentFromURL URL, uHTMLDoc
Debug.Print uHTMLDoc.Main.documentElement.outerHTML
End Sub
Private Sub GetHTMLDocumentFromURL(ByRef the_sURL As String, ByRef the_uHTMLDoc As HtmlDoc)
With the_uHTMLDoc
Set .Parent = New MSHTML.HTMLDocument
Set .Main = .Parent.createDocumentFromUrl(the_sURL, vbNullString)
' Wait for the document to load completely.
' This is because the transfer is asynchronous.
' It is possible that this string might be different if you have another
' language than English for Internet Explorer on the
' machine where the code is executed.
Do While .Main.readyState <> "complete"
DoEvents
Loop
End With
End Sub
我不知道你想做什么类型的解析,但请查看HTMLDocument类上的各种方法,如GetElementById()、GetElementsByName()和GetElementsByTagName()。好好看看类型库,并尝试一些实验来掌握它的窍门。