Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB6: Copying the entire contents of the webpage to the clipboard
#1
I need to copy the contents of the page.

Using Webbrowser control (IE11) in VB6, I copied the content this way:



Code:
1. Webbrowser1.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
2. Webbrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
3. Webbrowser1.ExecWB OLECMDID_CLEARSELECTION, OLECMDEXECOPT_DONTPROMPTUSER



The above code selects the entire page (equivalent to Ctrl+A),

then copies the entire page to the clipboard (Ctrl+C) and finally deselects the selection.



Could you point out how to copy the content using AntView ActiveX?



Your RequestCurrentHtml method works great and retrieves the source HTML code.



Is it possible to add a method to copy the content of the page?



Best Regards
Przemek
Reply
#2
Hi Przemek,

Do you want the Html or the Text?

If you only want the text then you could use javascript along the lines of:
Code:
  Dim jScript As String
  Dim varParams(0) As Variant
 
  jScript = "() => {" & vbCrLf
  jScript = jScript & "document.body.textContent;" & vbCrLf
  jScript = jScript & "}" & vbCrLf
  Document.BrowserDispatch EdgeWebBrowser.IDispatchPointer
  Document.RunAnonymousFunction 2, varParams, jScript

Then on the raised event retrieve decode the json object to remove the url encoding.
Code:
Private Sub Document_OnRunAnonymousFunction(ByVal Id As Long, ByVal Params As Variant, ByVal Data As String, ByVal Error As Long)
  Dim sData as String
  If Id = 2 Then
    sText = Document.DecodeJsonObjectString(Data)
  ElseIf Id = 3 Then

I think that should be it.

Once you have the text you can add it to the clipboard in the host application.
There's no need to do that from within the browser control as the clipboard is global to the Windows session.

If you have a bit I can add the above as a function to the document control similar to the currentHtml one to make it a bit easier to use.

--
Wil
Reply
#3
(2022-10-04, 08:49:50)wila Wrote: Hi Przemek,

Do you want the Html or the Text?

If you only want the text then you could use javascript along the lines of:
Code:
  Dim jScript As String
  Dim varParams(0) As Variant
 
  jScript = "() => {" & vbCrLf
  jScript = jScript & "document.body.textContent;" & vbCrLf
  jScript = jScript & "}" & vbCrLf
  Document.BrowserDispatch EdgeWebBrowser.IDispatchPointer
  Document.RunAnonymousFunction 2, varParams, jScript

Then on the raised event retrieve decode the json object to remove the url encoding.
Code:
Private Sub Document_OnRunAnonymousFunction(ByVal Id As Long, ByVal Params As Variant, ByVal Data As String, ByVal Error As Long)
  Dim sData as String
  If Id = 2 Then
    sText = Document.DecodeJsonObjectString(Data)
  ElseIf Id = 3 Then

I think that should be it.

Once you have the text you can add it to the clipboard in the host application.
There's no need to do that from within the browser control as the clipboard is global to the Windows session.

If you have a bit I can add the above as a function to the document control similar to the currentHtml one to make it a bit easier to use.

--
Wil

Thank you for the tip. I will check it soon.
 
On the other hand, my intention was to copy the whole content
I mean both text and images at one time.

However, adding the CurrentText method seems like a good idea for copying text.
It would be great if you could add such a method in the near future

--
Przemek
Reply
#4
Hi,

The Document CurrentText method is in the private build I send to you earlier today.

Getting both text and images is a different story.
I had done some preliminary work on that in the past, via the OnWebResourceResponseReceived event, but bumped into stability issues. So -for now- that did not make it.
Will have to look into that again, but no promises yet on when that will be.

There might be alternative ways for that, let me think about it for a bit.
--
Wil
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)