Does anybody know of a good way of parsing HTML in VB.Net.
I found a solution somewhere on the net using MSHTML.
I tried using it and to get it to work I had to add some code to my project:
Public Enum HRESULT
S_OK = 0
S_FALSE = 1
E_NOTIMPL = &H80004001
E_INVALIDARG = &H80070057
E_NOINTERFACE = &H80004002
E_FAIL = &H80004005
E_UNEXPECTED = &H8000FFFF
End Enum
<ComVisible(True), ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit : Inherits IPersist
Shadows Sub GetClassID(ByRef pClassID As Guid)
<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As HRESULT
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, _
<MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean) As HRESULT
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(), _
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As HRESULT
<PreserveSig()> Function InitNew() As HRESULT
End Interface
<ComVisible(True), ComImport(), Guid("0000010c-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersist
Sub GetClassID(ByRef pClassID As Guid)
End Interface
Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As IntPtr, ByVal fDeleteOnRelease As Boolean, _
ByRef ppstm As UCOMIStream) As Long
' Please note that i copied above IPersistStream definition from sp!ke. I owe him a drink ;).
End Class
And now I'm getting obsolete warnings:
Warning 1 'System.Runtime.InteropServices.UCOMIStream' is obsolete: 'Use System.Runtime.InteropServices.ComTypes.IStream instead. http://go.microsoft.com/fwlink/?linkid=14202'.
I didn't like the fact that I had to use the MSHTML stuff (cause I think IE uses it also, and we all know that IE sucks :) ) and that I had to add code the make it work.
Don't want to start a browser-war thread so neglect my last remark. :)
Is there a different (/better) approach of parsing html-pages in VB.Net.
Basically what I'm trying to do is get all the links (<a> tags) and embeds (<object> tag) on a page.
Thanks in advance for all you help!