facebook scraper given a user and passworc in csharp

Here is an example of scraping Facebook posts after logging in with user credentials using C# and Selenium:

main.cs
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace FacebookScraper
{
    class Program
    {
        static void Main(string[] args)
        {
            string email = "YOUR_EMAIL";
            string password = "YOUR_PASSWORD";
            string profileUrl = "PROFILE_URL";

            IWebDriver driver = new ChromeDriver();

            // Navigate to Facebook login page
            driver.Navigate().GoToUrl("https://www.facebook.com/login");

            // Enter email and password
            driver.FindElement(By.Id("email")).SendKeys(email);
            driver.FindElement(By.Id("pass")).SendKeys(password);

            // Click login button
            driver.FindElement(By.Id("loginbutton")).Click();

            // Navigate to profile page
            driver.Navigate().GoToUrl(profileUrl);

            // Find all posts on the page
            IReadOnlyCollection<IWebElement> posts = driver.FindElements(By.XPath("//div[@data-testid='fbfeed_story']"));

            // Print the text of each post
            foreach(IWebElement post in posts)
            {
                Console.WriteLine(post.Text);
            }

            // Close the driver
            driver.Quit();
        }
    }
}
1233 chars
43 lines

Note that this example uses Selenium and requires a ChromeDriver executable to be downloaded and added to your project. Additionally, this code is for educational purposes only and should not be used to violate Facebook's terms of service.

gistlibby LogSnag