0

I'am trying to make a script to programmatically.

I managed to get the hole html page to a string, Now I want to somehow click the elements that I have there. I'm kind of lost so any info could help.

I'v tried to get the document as a HtmlDocument but for some reason when I use the getElementById method it doesnt find the element.

Please, Any info would help.

Thanks.

Currently this is the code i'v got, It brings me up to the point where i have string that is it's value is the html document, now I need to some how extract the relavent tag and click it programmatically.

Thanks for your inputs, Still waiting for one that can help me.

string email = "someemail*";`enter code here`
string pw = "somepass";
string PostData = String.Format("email={0}&pass={1}", email, pw);

CookieContainer cookieContainer = new CookieContainer();

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.facebook.com/*******");
req.CookieContainer = cookieContainer;
req.Method = "POST";
req.ContentLength = PostData.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.AllowAutoRedirect = true;
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes(PostData);
req.ContentLength = loginDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(loginDataBytes, 0, loginDataBytes.Length);

HttpWebResponse webResp = (HttpWebResponse)req.GetResponse();

Stream datastream = webResp.GetResponseStream();
StreamReader reader = new StreamReader(datastream);
string sLine = "";
string json = "";
while (sLine != null)
{
    sLine = reader.ReadLine();
    json += sLine;
}
json.ToString();
Florian Koch
  • 1,372
  • 1
  • 30
  • 49
Daerik Fisher
  • 293
  • 3
  • 11
  • 20

3 Answers3

1

perhaps you might want to look at WaitN, it allows you to do all this really really easily

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
0

A "click on a link" is the same thing as sending a HTTP request. If you can parse the URI from the document you have, you can create the HTTP request separately and send that.

Jan
  • 2,168
  • 2
  • 19
  • 28
0

Clicking on a link is done by issuing a HTTP-Get for the href of the link.

If there is JavaScript interactivity, then you need to take a webbrowser element, and inject a javascript, that on document.ready executes document.getElementById("whatever").click()

See How do I programmatically click a link with javascript?

You can use HTML agility pack to parse a HTML document and extract the HREF argument.

Community
  • 1
  • 1
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442