|
-
Aug 30th, 2012, 06:44 PM
#1
Thread Starter
Junior Member
copy webBrowser text to clip board
What I'm trying to do is load a webpage, do some automated action and then highly text and copy it to the clipboard.
My code works up to highlighting the text (in step 3). If I run the program up to this point and then manually press control_C the text get placed on the clipboard.
However the code in step 4 is not placing the text in the clipboard. This should be a simple step. Am I making some stupid mistake?
Code:
Private Sub Tim_events_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tim_events.Tick
Static steps As Int16 = 1
If steps = 1 Then
'step 1: wait for the page to load
'then pause one time tick
Try
Dim dummy = WebBrowser.Document.Window()
Catch ex As Exception
'page has not finished loading
'wait
Return
End Try
Tim_events.Interval = 2500
ElseIf steps = 2 Then
'step 2: click radio button to get numbers
'schroll browser
WebBrowser.Document.Window.ScrollTo(75, 400)
'move mouse
SetCursorPos(165, 119)
'click
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Tim_events.Interval = 5000
ElseIf steps = 3 Then
'step 3: highlight desired text on browser
' ''schroll browser
WebBrowser.Document.Window.ScrollTo(0, 550)
'move mouse
SetCursorPos(16, 99)
'mouse down
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
'move mouse (drag)
SetCursorPos(46, 114)
'mouse up
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Tim_events.Interval = 5000
ElseIf steps = 4 Then
'step 4: copy to clip board by simulating type control_c
SendKeys.Send(Chr(3))
Tim_events.Interval = 3000
'ElseIf steps = 5 Then
' 'step 5: give focus to textbox
' Txt_workbox.Focus()
' Tim_events.Interval = 1500
'ElseIf steps = 6 Then
' step 6 paste data
' SendKeys.Send(Chr(22))
' Tim_events.Interval = 500
ElseIf steps = 7 Then
'step 7 Process data
'to do ......
steps = -1
Tim_events.Stop()
Tim_events.Interval = 500
End If
steps += 1
End Sub
-
Aug 30th, 2012, 07:54 PM
#2
Thread Starter
Junior Member
Re: copy webBrowser text to clip board
I found an easier way to accomplish what I want. The key piece of information is that it is not necessary to highlight text then copy it to the clip board. Instead the text can be obtained with the command
Code:
WebBrowser.Document.Body.InnerText
I am providing my working code below because it may be useful to someone latter searching for how to information.
Code:
Private Sub Tim_events_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tim_events.Tick
Static steps As Int16 = 1
If steps = 1 Then
'step 1: wait for the page to load
'then pause one time tick
Try
Dim dummy = WebBrowser.Document.Window()
Catch ex As Exception
'page has not finished loading
'wait
Return
End Try
Tim_events.Interval = 2500
ElseIf steps = 2 Then
'step 2: click radio button to get numbers
'schroll browser
WebBrowser.Document.Window.ScrollTo(75, 400)
'move mouse
SetCursorPos(165, 119)
'click
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Tim_events.Interval = 5000
ElseIf steps = 3 Then
'step 3 copy text into textbox
Txt_workbox.Text = WebBrowser.Document.Body.InnerText
ElseIf steps = 4 Then
'step 4 Process data
'to do ......
steps = -1
Tim_events.Stop()
Tim_events.Interval = 500
End If
steps += 1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|