|
-
Mar 4th, 2010, 12:27 AM
#1
Thread Starter
^:^...ANGEL...^:^
Fill data into a webpage and submit it
Hi there,
A question about auto filling data into webpages. I need to write a server side application mostly a console host app that makes some queries to the SQL Server database and gets a list of lets say students and their grades.
There is a third party website that gets updated at the moment some peoples working and filling that data manually.
I need to write a program that will basically open that webpage, login if required, navigate to certain page, click on certain tab, fill the data and hit the submit button. I don't think this part is that hard but the trouble comes with a client side dialog box. At the moment there is a client side dialogbox that shows up when you hit the submit button confirming the action and I need to press OK on that automatically.
I am allowed to write a windows application if not a console application and also use the web browser control to load the webpage rather than opening and interacting with the browser. If this makes it easier than so be it.
How would one go about achieving this? Is this even possible?
Cheers,
WRACK
-
Mar 4th, 2010, 06:13 AM
#2
Re: Fill data into a webpage and submit it
You can check in the SPy++ the name/class of that window...
And then in the code when you know that the window will pop up, you just need to get the window and create the code to push the button (SendMessage API Call)...
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Mar 4th, 2010, 06:22 PM
#3
Thread Starter
^:^...ANGEL...^:^
Re: Fill data into a webpage and submit it
Oh the good old SPY++. I was hoping there could be something easier than that.
You got any examples of doing so in .NET?
-
Mar 5th, 2010, 01:31 AM
#4
Thread Starter
^:^...ANGEL...^:^
Re: Fill data into a webpage and submit it
Allright new info. Can't use WebBrowser control as this has to be an unattended process.
I think I need to construct the web request myself and then post it and get a web response back as displayed in this example http://en.csharp-online.net/HTTP_Post
Does anyone here has experience dealing with this kinda things?
-
Mar 5th, 2010, 05:19 AM
#5
Re: Fill data into a webpage and submit it
I have a project at home with requests. Later i can post it here...
But to do that you'll need the complete info about the requests that are made to do the job, you can use for example wireshark to know what type of request and what data it's sent in every step (open webpage, login if required, navigate to certain page, click tab, fill the data and hit the submit button).
So you need to open the URI (MSDN sample helps you out), then you need to simulate the process with wireshark and get the info of each post...
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Mar 5th, 2010, 06:04 PM
#6
Thread Starter
^:^...ANGEL...^:^
Re: Fill data into a webpage and submit it
Yeah I realize it and I am using Fiddler2 to get the post info and stuff. It's an HTTPS page so I have to use something which can decode the stuff.
Thanks, I will look forward to see the project of yours.
-
Mar 5th, 2010, 06:33 PM
#7
Re: Fill data into a webpage and submit it
HTTPs maybe you'll have a problem here.... Never tried to do that...
In HTTP it's something like this:
vb.net Code:
'Just a little sample that can help you... you just need to see the original steps and change the code
Dim webClient As New System.Net.WebClient
webClient.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded") 'Need to know the type of headers :)
Dim bytesPost() As Byte = System.Text.Encoding.ASCII.GetBytes(String.Format("username={0}&password={1}", varUserName, varPass)) 'Prepare the data for the post...
Dim bytesAnswer() As Byte = webClient.UploadData("LinkToThePageThatAcceptsThePost", "POST", bytesPost)
Dim strAnswer As String = System.Text.Encoding.ASCII.GetString(bytesAnswer)
If strAnswer.Contains("Your Data Was Correctly Sent!") Then 'Some string that can be in the correct page
'If you verify that you are in the correct page
'Just prepare a new post, and send it... and so on...
Else
'The post was incorrect
End If
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Mar 9th, 2010, 12:09 AM
#8
Thread Starter
^:^...ANGEL...^:^
Re: Fill data into a webpage and submit it
Thanks Mickey.
I have tried your code and the code I have which uses HttpWebRequest and HttpWebResponse. I get the same result for the both of them. I am getting an error which gets displayed in HTML as below.
Code:
<noscript class="cErrorText">Active Scripting must be enabled for site to work.<br>Your current Internet Explorer settings have disabled this functionality.<br>Please enabled it before using site.</noscript>
Any idea on how do I tell the request or webclient that the scripting is enabled!!!
-
Mar 9th, 2010, 05:44 AM
#9
Re: Fill data into a webpage and submit it
THat's a big problem...
The scripting runs in the client, so i think there isn't any easy way to do what you want...
You can try to set the UserAgent of the request...
You can use a webbrowser control hidden...
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Mar 13th, 2010, 02:55 AM
#10
Thread Starter
^:^...ANGEL...^:^
Re: Fill data into a webpage and submit it
No using the control is not an option. This needs to be an unattended server side process.
Besides, adding an additional header of "Accept" with the value below seems to have done the trick so I am off to the next step.
Code:
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-silverlight, application/vnd.ms-excel, application/msword, */*"
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
|