1

您好,我正在尝试开发一个可以制作类似 Facebook 的自动机器人。我可以登录 Facebook 并可以导航到已登录的照片。但是我怎样才能点击照片的“赞”按钮?任何人都可以帮忙吗?

这是我的代码。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Get the response from the server and save the cookies from the first request..
             CookieCollection cookies = new CookieCollection();
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.facebook.com"); 
             request.CookieContainer = new CookieContainer();
             request.CookieContainer.Add(cookies);
             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
             cookies = response.Cookies;


            //Use cookieee
             string getUrl = "http://www.facebook.com/login.php?login_attempt=1";
             string postData = String.Format("email={0}&pass={1}", "email@ovi.com", "password");
             HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
             getRequest.CookieContainer = new CookieContainer();
             getRequest.CookieContainer.Add(cookies); //recover cookies First request
             getRequest.Method = WebRequestMethods.Http.Post;
             getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
             getRequest.AllowWriteStreamBuffering = true;
             getRequest.ProtocolVersion = HttpVersion.Version11;
             getRequest.AllowAutoRedirect = true;
             getRequest.ContentType = "application/x-www-form-urlencoded";
             CookieContainer container = new CookieContainer();
             container = getRequest.CookieContainer;

             byte[] byteArray = Encoding.ASCII.GetBytes(postData);
             getRequest.ContentLength = byteArray.Length;
             Stream newStream = getRequest.GetRequestStream(); //open connection
             newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
             newStream.Close();
             HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();



            //Now make like...but not working...
             HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://m.facebook.com/a/like.php?perm&ft_ent_identifier=495210693893173&gfid=AQAM3G9owHcMQG4B");
             req.CookieContainer = container;
             req.Method = "POST";
             //req.ContentType = "application/x-www-form-urlencoded";
             req.KeepAlive = true;
             try
             {
                 HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                 StreamReader sr = new StreamReader(res.GetResponseStream());
                 string source = sr.ReadToEnd();

                 StreamWriter myWriter = File.CreateText(@"D:\\test.txt");
                 myWriter.Write(source);
                 myWriter.Close();
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.ToString());
             }

            }
        }
    }

`

4

0 回答 0