我正在尝试使用C#在不同的网站上发布 [英] i am trying to post on different websites using c#
问题描述
我正在尝试使用c#在不同的网站上发布.我正在通过Web浏览器(已经在.Net中使用该浏览器)进行操作.我到目前为止已完成的代码如下,在此我成功打开了facebook,当我单击button_2时,它自动填写了登录表单,然后我成功登录了.这意味着我可以通过做一些更改来为其他站点执行此操作.现在这里的问题是我想将一些数据发布到不同的站点,例如链接或其他内容,并且当我成功登录后就像在下面的代码中所做的那样(允许说一个页面打开),并且在该页面中我必须填写一些数据数据或链接他们要求的字段.如何做才能进一步填写其他表单字段?而当我这样做后,我想将那个站点的最终结果保存到一个文本文件中吗?
请告诉我该怎么做?或任何有用的链接.
问候.
Hi, i am trying to post on different websites using c#. I am doing it through a web Browser( the one already in .Net). The code i have done so far is below, in this i am successfully opening facebook and when i click on button_2 it automatically fills the login form and i am successfully logged in then. This means i can do it for other sites as well by doing a little changes. Now the problem here is i want to post some data to different sites, like a link or something, and when i am logged in successfully like in did in the code below what lets say a page opens and in that page i have to fill some data or that link the fields they ask. How to do that to proceed further to fill other form fields? and when i have done that i want to save that final result from that site to a text file?
kindly tell me how to do that? or any useful links.
Regards.
private void button1_Click(object sender, EventArgs e)
{
webBrowserCtl.Navigate("https://login.facebook.com/login.php?login_attempt=1");
webBrowserCtl.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string s = webBrowser1.DocumentText;
// btnLogin.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
HtmlElement ele = webBrowserCtl.Document.GetElementById("email");
if (ele != null)
ele.InnerText = "email here";
ele = webBrowserCtl.Document.GetElementById("pass");
if (ele != null)
ele.InnerText = "password here";
ele = webBrowserCtl.Document.GetElementById("Login");
if (ele != null)
ele.InvokeMember("click");
}
推荐答案
嗨
为什么不为此目的使用System.Net.WebRequest.请看一下:
http://msdn.microsoft.com/zh-CN/library/debx8sh9.aspx
问候
帕旺
Hi
Why don''t you use System.Net.WebRequest for this purpose. please have a look at this :
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx
Regards
Pawan
这篇关于我正在尝试使用C#在不同的网站上发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!