{"id":13765150,"url":"https://github.com/SimpleBrowserDotNet/SimpleBrowser","last_synced_at":"2025-05-10T20:31:38.882Z","repository":{"id":40744782,"uuid":"1059594","full_name":"SimpleBrowserDotNet/SimpleBrowser","owner":"SimpleBrowserDotNet","description":"A flexible and intuitive web browser engine designed for automation tasks. Built on .NET Standard 2.1.","archived":false,"fork":false,"pushed_at":"2023-11-26T16:57:58.000Z","size":2189,"stargazers_count":365,"open_issues_count":20,"forks_count":104,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-04-05T22:11:21.154Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimpleBrowserDotNet.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2010-11-07T17:12:16.000Z","updated_at":"2025-02-18T13:47:23.000Z","dependencies_parsed_at":"2024-04-18T14:02:49.588Z","dependency_job_id":null,"html_url":"https://github.com/SimpleBrowserDotNet/SimpleBrowser","commit_stats":null,"previous_names":["axefrog/simplebrowser"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleBrowserDotNet%2FSimpleBrowser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleBrowserDotNet%2FSimpleBrowser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleBrowserDotNet%2FSimpleBrowser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleBrowserDotNet%2FSimpleBrowser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimpleBrowserDotNet","download_url":"https://codeload.github.com/SimpleBrowserDotNet/SimpleBrowser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253480493,"owners_count":21915248,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T16:00:34.586Z","updated_at":"2025-05-10T20:31:34.279Z","avatar_url":"https://github.com/SimpleBrowserDotNet.png","language":"C#","readme":"SimpleBrowser\r\n=============\r\nSimpleBrowser is a lightweight, yet highly capable browser automation engine designed for automation and testing scenarios.\r\nIt provides an intuitive API that makes it simple to quickly extract specific elements of a page using a variety of matching\r\ntechniques, and then interact with those elements with methods such as `Click()`, `SubmitForm()` and many more. SimpleBrowser\r\ndoes not support JavaScript, but allows for manual manipulation of the user agent, referrer, request headers, form values and\r\nother values before submission or navigation.\r\n\r\nRequirements\r\n------------\r\n* .NET Standard 2.0 compatible runtime\r\n\r\nFeatures\r\n--------\r\n* Multiple ways of locating and interacting with page elements. The browser session is completely scriptable.\r\n* A highly permissive HTML parser that converts any HTML, no matter how badly formed, to a valid XDocument object\r\n* Automatic cookie/session management\r\n* Extensive logging support with attractive and comprehensive html log file output to make it easy to identify problems loading and automating browsing sessions\r\n\r\nExample\r\n-------\r\n\r\n``` c#\r\nclass Program\r\n{\r\n\tstatic void Main(string[] args)\r\n\t{\r\n\t\tvar browser = new Browser();\r\n\t\ttry\r\n\t\t{\r\n\t\t\t// log the browser request/response data to files so we can interrogate them in case of an issue with our scraping\r\n\t\t\tbrowser.RequestLogged += OnBrowserRequestLogged;\r\n\t\t\tbrowser.MessageLogged += new Action\u003cBrowser, string\u003e(OnBrowserMessageLogged);\r\n\r\n\t\t\t// we'll fake the user agent for websites that alter their content for unrecognised browsers\r\n\t\t\tbrowser.UserAgent = \"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10\";\r\n\r\n\t\t\t// browse to GitHub\r\n\t\t\tbrowser.Navigate(\"http://github.com/\");\r\n\t\t\tif(LastRequestFailed(browser)) return; // always check the last request in case the page failed to load\r\n\r\n\t\t\t// click the login link and click it\r\n\t\t\tbrowser.Log(\"First we need to log in, so browse to the login page, fill in the login details and submit the form.\");\r\n\t\t\tvar loginLink = browser.Find(\"a\", FindBy.Text, \"Login\");\r\n\t\t\tif(!loginLink.Exists)\r\n\t\t\t\tbrowser.Log(\"Can't find the login link! Perhaps the site is down for maintenance?\");\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tloginLink.Click();\r\n\t\t\t\tif(LastRequestFailed(browser)) return;\r\n\r\n\t\t\t\t// fill in the form and click the login button - the fields are easy to locate because they have ID attributes\r\n\t\t\t\tbrowser.Find(\"login_field\").Value = \"youremail@domain.com\";\r\n\t\t\t\tbrowser.Find(\"password\").Value = \"yourpassword\";\r\n\t\t\t\tbrowser.Find(ElementType.Button, \"name\", \"commit\").Click();\r\n\t\t\t\tif(LastRequestFailed(browser)) return;\r\n\r\n\t\t\t\t// see if the login succeeded - ContainsText() is very forgiving, so don't worry about whitespace, casing, html tags separating the text, etc.\r\n\t\t\t\tif(browser.ContainsText(\"Incorrect login or password\"))\r\n\t\t\t\t{\r\n\t\t\t\t\tbrowser.Log(\"Login failed!\", LogMessageType.Error);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t// After logging in, we should check that the page contains elements that we recognise\r\n\t\t\t\t\tif(!browser.ContainsText(\"Your Repositories\"))\r\n\t\t\t\t\t\tbrowser.Log(\"There wasn't the usual login failure message, but the text we normally expect isn't present on the page\");\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbrowser.Log(\"Your News Feed:\");\r\n\t\t\t\t\t\t// we can use simple jquery selectors, though advanced selectors are yet to be implemented\r\n\t\t\t\t\t\tforeach(var item in browser.Select(\"div.news .title\"))\r\n\t\t\t\t\t\t\tbrowser.Log(\"* \" + item.Value);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tcatch(Exception ex)\r\n\t\t{\r\n\t\t\tbrowser.Log(ex.Message, LogMessageType.Error);\r\n\t\t\tbrowser.Log(ex.StackTrace, LogMessageType.StackTrace);\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tvar path = WriteFile(\"log-\" + DateTime.UtcNow.Ticks + \".html\", browser.RenderHtmlLogFile(\"SimpleBrowser Sample - Request Log\"));\r\n\t\t\tProcess.Start(path);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic bool LastRequestFailed(Browser browser)\r\n\t{\r\n\t\tif(browser.LastWebException != null)\r\n\t\t{\r\n\t\t\tbrowser.Log(\"There was an error loading the page: \" + browser.LastWebException.Message);\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\tstatic void OnBrowserMessageLogged(Browser browser, string log)\r\n\t{\r\n\t\tConsole.WriteLine(log);\r\n\t}\r\n\r\n\tstatic void OnBrowserRequestLogged(Browser req, HttpRequestLog log)\r\n\t{\r\n\t\tConsole.WriteLine(\" -\u003e \" + log.Method + \" request to \" + log.Url);\r\n\t\tConsole.WriteLine(\" \u003c- Response status code: \" + log.ResponseCode);\r\n\t}\r\n\r\n\tstatic string WriteFile(string filename, string text)\r\n\t{\r\n\t\tvar dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"Logs\"));\r\n\t\tif(!dir.Exists) dir.Create();\r\n\t\tvar path = Path.Combine(dir.FullName, filename);\r\n\t\tFile.WriteAllText(path, text);\r\n\t\treturn path;\r\n\t}\r\n}\r\n```\r\n","funding_links":[],"categories":["C# #","Tools"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSimpleBrowserDotNet%2FSimpleBrowser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSimpleBrowserDotNet%2FSimpleBrowser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSimpleBrowserDotNet%2FSimpleBrowser/lists"}