C# Getting info from a web id - c#

I want to get text from a website, but from a certain element, does any one have any clues?
From example the code I have to make text form a text box to a website textbox is
webBrowser1.Document
.GetElementById("MySchool_login")
.SetAttribute("value", textBox1.Text);

What you want to do is called as screen scrapping. You can use Watin for this. Or else you can use WebResponse and WebRequest to achieve this also.

Related

Javascript Auto Form Filling

I am trying to autologin into facebook using javascript and iam using awesomium as webcontrol in my c# application which can execute javascripts.i need the right javascript to autofill both textbox and click the login button
URL:https://www.facebook.com/login
string pass="password";
string email="example#example.com";
webControl1.ExecuteJavascript("document.getElementById('email').value="+email);
webControl1.ExecuteJavascript("document.getElementById('pass').value="+pass);
webControl1.ExecuteJavascript("document.getElementsByName('u_0_1').click()");
but its not working can anyone figure this out
Your setting the same email field twice. Try...
webControl1.ExecuteJavascript("document.getElementById('email').value="+email);
webControl1.ExecuteJavascript("document.getElementById('pass').value="+password)
webControl1.ExecuteJavascript("document.getElementById('u_0_n').click()");
I'm not sure if password is the correct id, you'll have to inspect the element yourself.

Read content from a URL, place into a textbox

I'm trying to read lines from a website and then, copy it into my textBox2.
textBox1 will have a website's URL like http://example.com.
When I click on button1 I'd like to read HTML content from the above URL, and please that info textBox2.
Should I use HtmlAgilityPack?
How can this be done?
2 =================================================
So, for example, i copy this link into my "textBox1"
http://www.mineshaftersquared.com/server/DareCraft#
So, is there a way to make app copy everything from:
//*[#id="Plugins"]
to
//*[#id="rightInfo"]/section[2]/div/div[1]/table[2]
/this is XPath
/It don't have to in XPath, but this was the only way I could show.
You don't install HtmlAgilityPack, you reference if from your project.
Read about WebClient class (OpenRead method), you probably want to use it to get the pages.
Here is a tutorial you might want to start with:
http://www.codeproject.com/Articles/33798/HTTP-GET-with-NET-WebClient

Filling a HTML form with C#

I need help with connecting to a certain website via my username & password.
With WebClient I can fill the username field and the password field, but how do I invoke the click method of the button?
And How can I fill a specific textBox that doesn't have an ID?
I tried doing this with webBrowser, but every time I navigate I have to use a new function every time, which makes the work much harder.
Thanks.
What you're trying to do is wrong. If you want to Post some data to a web address (a URL), simply create a web form (a simple HTML form), fill it, and then send it. Just consider these notes:
Your HTML's form action should be the exact URL of the form you're imitating.
Your input controls should have the same name attribute value.
For more information, see Form Spoofing
Look at the web browser control and see if you can use that inside your windows form to perform the task that you are doing. Once you are satisfied with the results, you can make the web browser control invisible, and it'll work just like you do with web response and request calls.
View the source code and find the id of the button (say "Login").
Then use:
HtmlElement elem = webBrowser1.Document.GetElementById("Login");
if (elem != null)
elem.InvokeMember("click");

Gecko usage in C# (geckofx)

There are some things that I didn't find how to do using geckofx:
Get the URL of a clicked link.
Display print preview window.
Does this functionality exist in geckofx? If not, what's the best way
to achieve it in a C# project that uses GeckoWebBrowser to display html pages?
Thanks
To get url of clicked link you can use:
void domClicked(object sender, GeckoDomMouseEventArgs e)
{
if(geckoWebBrowser1.StatusText.StartsWith("http"))
{
MessageBox.Show(geckoWebBrowser1.StatusText);//forward status text string somewhere
}
}
To show print dialog box you can use:
geckoWebBrowser1.Navigate("javascript:print()");
OnNaviagted event should give you the link, and look for the print interfaces nsIPrintingPromptService::ShowPrintDialog in Geckofx.
geckoWebBrowser.url
That will give you the url at any point I believe where geckoWebBrowser is the name of the control, however as pointed out you'll be able to get it from the document completed and navigated events using e.url .
For printing, see this forum thread. Make sure to read it all before starting. Essentially you'll have to patch and recompile GeckoFX.

Getting url of a page once making a form submission

I am designing a winforms based testing app (which is based upon WatiN). I specify a page to test and the value to insert into a textbox, and then click the corresponding button.
Is it possible to add a query string to the request I make (when clicking button) and then get the URL of the next page? Based on this, I need to screen scrape it.
Not sure about Watin syntax, but in Watir (Ruby version) you can get URL of the page displayed in browser with
browser.url
Or do you need to get URL of the next page before you open it?
Based on your comment to AmitK, Ċ½eljko's answer is right.
In WatiN (and C#), the syntax is:
Console.WriteLine("The current page is:" + ie.Url.ToString());
(just in case: 'ie' is the browser reference, use whatever object you use to enter text and click buttons)
What exactly do you mean by "next page" ? Does the form when submitted redirect to another page? If so, you will receive a HTTP 302/303 status code with the URL of the next page.

Categories