|
-
Feb 15th, 2011, 10:36 AM
#1
Thread Starter
PowerPoster
[RESOLVED] simulate mouse r/click,Copy & paste...
it is an unusual question please be patient
My series of intentions;
(1) open a web page
(2) select all contents, as same as -> edit->select all
(3) Copy the contents to a excel file (Say for ex into CELL A1)
(4) clear the clipboard
(5) open another web page & continue
basic ideas please?
Sorry if my question irritates you please
Last edited by make me rain; Feb 15th, 2011 at 10:38 AM.
Reason: missing information
-
Feb 15th, 2011, 10:53 AM
#2
Frenzied Member
Re: simulate mouse r/click,Copy & paste...
Basically you need to open the webpage using an WebBrowser Control, then you can access the various element of the webpage and get the data of those elements
This Link Should help you
-
Feb 15th, 2011, 11:02 AM
#3
Re: simulate mouse r/click,Copy & paste...
If you are doing this with a webbrowser you can use sendkeys to select all and copy it to the clipboard
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("A Url")
End Sub
Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
WebBrowser1.Focus()
SendKeys.SendWait("^a")
SendKeys.SendWait("^c")
End Sub
Or you could just get the html source from the webbrowser document
Last edited by BlindSniper; Feb 15th, 2011 at 11:06 AM.
-
Feb 15th, 2011, 11:39 AM
#4
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
thank you ashish & sniper
so far i have not done any work on webbrowser control
let me try
-
Feb 16th, 2011, 12:44 AM
#5
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
code to works some extent, but next page not loading ? !
further advise please
vb.net Code:
Imports System.Web
Public Class web
Inherits System.Windows.Forms.Form
Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me.WebBrowser1
.Navigate("http://203.176.113.112/CMSREPORT/JSP/nonloginreports/CMSAnalysisStatistics.do?hmode=home")
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With Me.WebBrowser1
Me.WebBrowser1.Document.Forms.Item(0).DomElement(1).value = "UBL1425"
'in fact i want to si mulate click go button ( i mean label)
Me.WebBrowser1.Document.Forms(0).InvokeMember("submit")
'why yhe next page is not loading here ?? !!!!
'but if i click manually on the go label next page is loading
End With
End Sub
-
Feb 16th, 2011, 02:17 PM
#6
Re: simulate mouse r/click,Copy & paste...
Try this:
vb.net Code:
Public Class web Private submitted As Boolean = False Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WebBrowser1.Navigate("http://203.176.113.112/CMSREPORT/JSP/nonloginreports/CMSAnalysisStatistics.do?hmode=home") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '' fill textbox and click button Dim crewId As HtmlElement = WebBrowser1.Document.All("crewId") crewId.SetAttribute("value", "UBL1425") crewId.NextSibling.InvokeMember("click") submitted = True End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted '' write to text file If submitted AndAlso WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Exit Sub Dim pageContents As String = WebBrowser1.Document.Body.InnerText IO.File.WriteAllText("C:\Temp\test.CSV", pageContents) End Sub End Class
-
Feb 17th, 2011, 09:03 AM
#7
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
pradeep ji thank you
in fact i am going through http://msdn.microsoft.com/en-us/libr...mlelement.aspx here, very wast i am not confident of finishing it practically.
your code works fine.
kindly advise me , in the next page opens there, it gives me options with radio buttons & one button
if you don't mind can you please advise further to load the next page with options.
-
Feb 17th, 2011, 02:40 PM
#8
Re: simulate mouse r/click,Copy & paste...
I see 5 radiobuttons and 2 command buttons.
Which option you want to select and which button to click?
-
Feb 17th, 2011, 04:48 PM
#9
Re: simulate mouse r/click,Copy & paste...
vb.net Code:
Public Class web Private stage As Integer = 0 Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WebBrowser1.Navigate("http://203.176.113.112/CMSREPORT/JSP/nonloginreports/CMSAnalysisStatistics.do?hmode=home") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '' fill textbox and click button stage = 1 Dim crewId As HtmlElement = WebBrowser1.Document.All("crewId") crewId.SetAttribute("value", "UBL1425") crewId.NextSibling.InvokeMember("click") End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Exit Sub Select Case stage Case 1 '' write to text file Dim pageContents As String = WebBrowser1.Document.Body.InnerText IO.File.WriteAllText("C:\Temp\test.CSV", pageContents) '' proceed to next stage stage = 2 Dim myElement As HtmlElement myElement = GetInputControl("durationtype", "FORTNIGHT") ' set values myElement.InvokeMember("click") myElement = GetInputControl("currentSlot", "CURRENT") ' set values myElement.InvokeMember("click") myElement = GetInputControl("submit", "CrewRunDetails") ' click button myElement.InvokeMember("click") Case 2 '' you will get the 2nd page here.. '' do whatever you want to with it. MsgBox(WebBrowser1.Document.Body.InnerText) End Select End Sub Private Function GetInputControl(ByVal name As String, ByVal value As String) As HtmlElement Return (From element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("INPUT") _ Where element.Name = name AndAlso element.GetAttribute("value") = value).FirstOrDefault End Function End Class
-
Feb 18th, 2011, 06:02 AM
#10
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
pradeep ji, thank you & sorry i am troubling you too much 
is it possible to save the contents of the table which opens after the radio + command button click. in to a database,
what i tried was,
save all the employee records
contents of the web page table
( crewid,crewname,slot on the top )
and his relative rows in the table in to a MySQL table.
hence i thought of saving the final web page contents in to an excel &
from there in to an database,because it was easy for me to pickup crew name,id, etc with a cell reference
but this activity is taking huge time,space...
and appears to be derailed from the track
kindly advise please
-
Feb 18th, 2011, 06:52 AM
#11
Re: simulate mouse r/click,Copy & paste...
So what code do you have till now and what specifically is not working?
You should be able to easily modify post #9 to your needs.
 
-
Feb 18th, 2011, 07:19 AM
#12
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
fine
is it possible to pick the data in
web page table rows
to
database fields directly.
instead of saving the page contents into .csv file & from there in to an database
-
Feb 18th, 2011, 08:38 AM
#13
Re: simulate mouse r/click,Copy & paste...
There is hardly anything you can think of logically but not able to program it. 
So what code do you have till now? Which database?
If you provide clear description of your problem and what you have tried till now, there are many here who would be able to help you out with your problems.
-
Feb 18th, 2011, 09:18 AM
#14
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
So for is good,
ultimate the task is :
automating the
importing of data basing on crewID from the web page into MySQL data base.
So for covered:
Opened web page and saved the data into .xls file
what i would like to do now is:
instead of saving pagecontent or innerHTML of the web page as an .xls file & then read from .xls file in to MySQL database , i want to save the read & save the data in to the database.
i will post the code now sir...
-
Feb 18th, 2011, 10:18 AM
#15
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
Task:
reading from the file saved as .xls
**************************
way 1.
i can't connect to the file file saved as xls. bug i will get is
"External table is not in the expected format."
this case was clarified by jmc earlier why i can't connect.
vb.net Code:
Dim ExlCnn As New OleDb.OleDbConnection
Dim ExlFilepath As String = "e:\Impo.xls"
Dim ExlCnns As String = _
"Provider=Microsoft.ACE.OLEDB.12.0;" _
& " Data Source=" & ExlFilepath _
& ";Extended Properties='Excel 12.0;HDR=NO';"
ExlCnn.ConnectionString = ExlCnns
If ExlCnn.State <> ConnectionState.Open Then
ExlCnn.Open()
End If
MessageBox.Show(ExlCnn.State)
way 2.
'i must open the saved excel file
'read / loop through the required data & then save the values into MySQL
'This process is slow,
'**** HENCE I WANT TO READ DATA FROM THE WEB PAGE IT SELF*******
vb.net Code:
Dim ExlFilepath As String = "e:\Impo.xls"
Dim Exl As New Excel.Application
Dim Exl_Wb As Excel.Workbook
Dim Exl_Sheet As Excel.Worksheet
Exl_Wb = Exl.Workbooks.Add
Exl_Sheet = Exl_Wb.Worksheets(1)
Exl.Workbooks.Open(ExlFilepath)
'here i am reading the field values
With Exl_Sheet
Dim CrewId As String = .Range("b5").Cells.Value
Dim CrewName As String = .Range("b6").Cells.Value
Dim Slot As String = .Range("e4").Cells.Value
Dim PFnumber As String = .Range("d6").Cells.Value
End With
'update the primary crew data
' Call uPdateBasicCrewData(CrewID, cREWNAME, SloT, PFnumber)
Exl_Wb.Close()
Exl.Quit()
Exl_Sheet = Nothing
Exl_Wb = Nothing
Exl = Nothing
Further advise please sir
-
Feb 18th, 2011, 02:08 PM
#16
Re: simulate mouse r/click,Copy & paste...
You don't need any excel file or any other file as an intermediate. You can always access the data directly from the html page.
vb.net Code:
Case 2 '' you will get the 2nd page here.. Dim htmlTable As HtmlElement = WebBrowser1.Document.GetElementsByTagName("TABLE")(5) Dim myList = From tr In htmlTable.GetElementsByTagName("TR") _ Let td As HtmlElementCollection = tr.GetElementsByTagName("TD") _ Where td.Count = 16 _ Select New With {.Date = td(0).InnerText, _ .Rest = td(1).InnerText, _ .SignOnTime = td(2).InnerText, _ .SignOnFrom = td(3).InnerText, _ .Train = td(4).InnerText _ ' -- add other fields in the same way -- } ' Now you have everything in myList ' You can access the items from this list and fill into your datatable or whatever you have End Select
-
Feb 19th, 2011, 01:07 AM
#17
Thread Starter
PowerPoster
Re: simulate mouse r/click,Copy & paste...
vow........
great & thanks
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
|