Results 1 to 5 of 5

Thread: ie page source

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    3

    Question ie page source

    is there a way to get vb to get the source out of an open IE page, i dont want to do it via winsock-directly from ie? -thanks

  2. #2
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711
    try this:
    http://www.thevbzone.com/modHtmlSource.bas

    to get the URL from IE use this:

    VB Code:
    1. Public Function EnumProc(ByVal app_hwnd As Long, ByVal _
    2.     lParam As Long) As Boolean
    3. Dim buf As String * 1024
    4. Dim title As String
    5. Dim length As Long
    6.  
    7.     ' Get the window's title.
    8.     length = GetWindowText(app_hwnd, buf, Len(buf))
    9.     title = Left$(buf, length)
    10.  
    11.     ' See if the title ends with " - Netscape".
    12.     If Right$(title, 30) = " - Microsoft Internet Explorer" _
    13.         Then
    14.         ' This is it. Find the ComboBox information.
    15.         frmWindowList.lblAddress = EditInfo(app_hwnd)
    16.  
    17.         ' Stop searching.
    18.         EnumProc = 0
    19.     Else
    20.         ' Continue searching til find it.
    21.         EnumProc = 1
    22.     End If
    23. End Function
    24.  
    25. ' If this window is of the Edit class, return
    26. ' its contents. Otherwise search its children
    27. ' for an Edit object.
    28. Public Function EditInfo(window_hwnd As Long) As String
    29. Dim txt As String
    30. Dim buf As String
    31. Dim buflen As Long
    32. Dim child_hwnd As Long
    33. Dim children() As Long
    34. Dim num_children As Integer
    35. Dim i As Integer
    36.  
    37.     ' Get the class name.
    38.     buflen = 256
    39.     buf = Space$(buflen - 1)
    40.     buflen = GetClassName(window_hwnd, buf, buflen)
    41.     buf = Left$(buf, buflen)
    42.    
    43.     ' See if we found an Edit object.
    44.     If buf = "Edit" Then
    45.         EditInfo = WindowText(window_hwnd)
    46.         Exit Function
    47.     End If
    48.    
    49.     ' It's not an Edit object. Search the children.
    50.     ' Make a list of the child windows.
    51.     num_children = 0
    52.     child_hwnd = GetWindow(window_hwnd, GW_CHILD)
    53.     Do While child_hwnd <> 0
    54.         num_children = num_children + 1
    55.         ReDim Preserve children(1 To num_children)
    56.         children(num_children) = child_hwnd
    57.        
    58.         child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
    59.     Loop
    60.    
    61.     ' Get information on the child windows.
    62.     For i = 1 To num_children
    63.         txt = EditInfo(children(i))
    64.         If txt <> "" Then Exit For
    65.     Next i
    66.  
    67.     EditInfo = txt
    68. End Function
    69.  
    70. ' Return the text associated with the window.
    71. Public Function WindowText(window_hwnd As Long) As String
    72. Dim txtlen As Long
    73. Dim txt As String
    74.  
    75.     WindowText = ""
    76.     If window_hwnd = 0 Then Exit Function
    77.    
    78.     txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, _
    79.         0)
    80.     If txtlen = 0 Then Exit Function
    81.    
    82.     txtlen = txtlen + 1
    83.     txt = Space$(txtlen)
    84.     txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, _
    85.         ByVal txt)
    86.     WindowText = Left$(txt, txtlen)
    87. End Function
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    3
    uh by looking at that it looks like all it does is get the url-this is much easier to do that, and thats not what im looking for -more liek the page source as in right click, view source :P - tell me if im wrong though, i only glanced at it

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    Private Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE


    Private Sub Command1_Click()
    Dim ieframe As Long
    Dim workerw As Long
    Dim rebarwindow As Long
    Dim comboboxex As Long
    Dim combobox As Long
    Dim edit As Long

    ieframe& = FindWindow("ieframe", vbNullString)
    workerw& = FindWindowEx(ieframe&, 0&, "workerw", vbNullString)
    rebarwindow& = FindWindowEx(workerw&, 0&, "rebarwindow32", vbNullString)
    comboboxex& = FindWindowEx(rebarwindow&, 0&, "comboboxex32", vbNullString)
    combobox& = FindWindowEx(comboboxex&, 0&, "combobox", vbNullString)
    edit& = FindWindowEx(combobox&, 0&, "edit", vbNullString)

    Dim Text As String
    Dim TextLen As Long
    TextLen& = SendMessageLong(edit&, WM_GETTEXTLENGTH, 0&, 0&)
    Text$ = String(TextLen& + 1, Chr(0))
    Call SendMessageByString(edit&, WM_GETTEXT, TextLen& + 1, Text$)
    Text$ = Left(Text$, TextLen&)

    Text1.Text = Text$
    End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    3
    anyone

  5. #5
    Addicted Member
    Join Date
    Mar 2004
    Posts
    146
    Once you have the URL, just use the Inet control (Ctrl T, check Microsoft Internet Control 6.0), and here's your code:

    VB Code:
    1. Dim pageHTML as String
    2. pageHTML = Inet.OpenURL (WindowText)
    3. MsgBox "Here's your source: " & pageHTML

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width