{"id":28331214,"url":"https://github.com/hasdata/login-examples","last_synced_at":"2026-04-12T15:37:09.303Z","repository":{"id":294238376,"uuid":"979459792","full_name":"HasData/login-examples","owner":"HasData","description":"This repository provides practical examples of handling authentication in web scraping using both Python and Node.js. It covers multiple login techniques - from simple form submissions to handling cookies, sessions and CSRF tokens.","archived":false,"fork":false,"pushed_at":"2025-05-19T13:35:27.000Z","size":333,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T02:37:50.212Z","etag":null,"topics":["browser-automation","cookie-handling","csrf","login-automation","nodejs","playwright","puppeteer","python","selenium","seleniumbase","session-persistence"],"latest_commit_sha":null,"homepage":"https://hasdata.com/blog/scrape-website-with-login-python","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HasData.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-07T14:42:42.000Z","updated_at":"2025-05-19T13:42:57.000Z","dependencies_parsed_at":"2025-05-19T14:45:01.682Z","dependency_job_id":"d81ca853-ab7d-4b80-8930-b9f1f04f1be4","html_url":"https://github.com/HasData/login-examples","commit_stats":null,"previous_names":["hasdata/login-examples"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HasData/login-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasData%2Flogin-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasData%2Flogin-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasData%2Flogin-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasData%2Flogin-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HasData","download_url":"https://codeload.github.com/HasData/login-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HasData%2Flogin-examples/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265205782,"owners_count":23727513,"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":["browser-automation","cookie-handling","csrf","login-automation","nodejs","playwright","puppeteer","python","selenium","seleniumbase","session-persistence"],"created_at":"2025-05-26T18:29:06.195Z","updated_at":"2026-04-12T15:37:09.189Z","avatar_url":"https://github.com/HasData.png","language":"JavaScript","readme":"![Python](https://img.shields.io/badge/python-3.10+-blue)\r\n![Node.js](https://img.shields.io/badge/node.js-18+-green)\r\n\r\n# Login Automation Examples (Python \u0026 Node.js)\r\n[![HasData_bannner](banner.png)](https://hasdata.com/)\r\n\r\nThis repository contains practical login automation examples using **Python** and **Node.js**. It demonstrates how to handle different authentication flows: from basic form submissions to CSRF-protected logins and browser automation with Selenium, Puppeteer, SeleniumBase and Playwright.\r\n\r\n\r\n## Table of Contents\r\n\r\n1. [Requirements](#requirements)\r\n2. [Project Structure](#project-structure)\r\n3. [Login  Examples](#login-examples)\r\n   - [Simple Login](#simple-login)\r\n   - [CSRF Token Login](#csrf-token-login)\r\n   - [Selenium/Puppeteer Login](#seleniumpuppeteer-login)\r\n   - [SeleniumBase/Playwright Login](#seleniumbaseplaywright-login)\r\n   - [Session Persistence](#session-persistence)\r\n   - [Cookie Handling](#cookie-handling)\r\n4. [Disclaimer](#disclaimer)\r\n\r\n\r\n## Requirements\r\n\r\n**Python 3.10+** or **Node.js 18+**\r\n\r\n### Python Setup\r\n\r\nRequired packages include:\r\n\r\n* `requests`\r\n* `beautifulsoup4`\r\n* `selenium`\r\n* `seleniumbase`\r\n\r\nCommand: \r\n\r\n```bash\r\npip install requests beautifulsoup4 selenium seleniumbase\r\n```\r\n\r\n### Node.js Setup\r\n\r\n\r\nIncludes:\r\n\r\n* `axios`\r\n* `puppeteer`\r\n* `playwright`\r\n\r\nCommand:\r\n\r\n```bash\r\nnpm install axios puppeteer playwright\r\n```\r\n\r\n## Project Structure\r\n\r\n```\r\nlogin-examples/\r\n│\r\n├── python/\r\n│   ├── simple_login_get.py\r\n│   ├── simple_login_post.py\r\n│   ├── csrf_token_login.py\r\n│   ├── selenium_login.py\r\n│   ├── seleniumbase_login.py      \r\n│   ├── session_persistence.py\r\n│   ├── cookie_handling.py\r\n│\r\n├── nodejs/\r\n│   ├── simple_login.js\r\n│   ├── simple_login_post.js\r\n│   ├── csrf_token_login.js\r\n│   ├── puppeteer_login.js\r\n│   ├── playwright_login.js         \r\n│   ├── session_persistence.js\r\n│   ├── cookie_handling.js\r\n│\r\n└── README.md\r\n```\r\n\r\nEach script is self-contained and targets a different type of login logic.\r\n\r\n##  Login Examples\r\n\r\nReplace `URL`, `username`, and `password` with your actual values before running.\r\n\r\n### Simple Login\r\n\r\nDemonstrates a simple POST/GET login using email and password. This method works by sending the credentials directly via a POST/GET request.\r\n\r\n| Description             | Python                                           | Node.js                                                                 |\r\n| ----------------------- | -------------------------------------------- | ----------------------------------------------------------------- |\r\n| **Authenticate (POST)** | `requests.post(login_url, data=payload)`         | `axios.post(loginUrl, payload)`                                         |\r\n| **Authenticate (GET)**  | `requests.get(login_url, auth=('user', 'pass'))` | `axios.get(loginUrl, { auth: { username: 'user', password: 'pass' } })` |\r\n\r\n\r\n### CSRF Token Login\r\n\r\nShows how to handle CSRF tokens during login. It extracts the CSRF token from the page and includes it in the login request for protection against CSRF attacks.\r\n\r\n\r\n| Description                  | Python                                                                                    | Node.js                                                                                                                                        |\r\n| ---------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |\r\n| **GET login page**           | `resp = session.get(login_url)`\u003cbr\u003e`resp.raise_for_status()`                              | `const getResp = await axios.get(loginUrl, { withCredentials: true });`                                                                        |\r\n| **Extract CSRF token**       | `csrf_token = soup.select_one(\"input[name='_token']\")['value']`                           | `const $ = cheerio.load(getResp.data);`\u003cbr\u003e`const csrf = $('input[name=\"_token\"]').attr('value');`                                             |\r\n| **POST credentials + token** | `session.post(login_url, data=payload)`\u003cbr\u003e`post_resp.raise_for_status()`                 | `await axios.post(loginUrl, payload.toString(), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, withCredentials: true });` |\r\n| **GET protected page**       | `protected = session.get(protected_url)`\u003cbr\u003e`protected.raise_for_status()`                | `const protectedResp = await axios.get(protectedUrl, { withCredentials: true });`                                                              |\r\n\r\n\r\n### Selenium/Puppeteer Login\r\n\r\nUses **Selenium** to automate login by interacting with the page and filling in the login form (useful for sites that require interaction with JavaScript elements or CAPTCHAs).\r\n\r\n\r\n| Description        | Python                                                            | Node.js                                                       |\r\n| ------------------ | ----------------------------------------------------------------- | ------------------------------------------------------------- |\r\n| **Init browser**   | `driver = webdriver.Chrome(...)`                                  | `const browser = await puppeteer.launch({ headless: true });` |\r\n| **Go to page**     | `driver.get(\"URL\")`                             | `await page.goto(\"URL\")`                    |\r\n| **Enter login**    | `driver.find_element(...,\"email\").send_keys(\"admin@example.com\")` | `await page.type('input[name=\"email\"]','admin@example.com')`  |\r\n| **Enter password** | `driver.find_element(...,\"password\").send_keys(\"password\")`       | `await page.type('input[name=\"password\"]','password')`        |\r\n| **Submit form**    | `driver.find_element(...,'button[type=\\\"submit\\\"]').click()`      | `await page.click('button[type=\\\"submit\\\"]')`                 |\r\n\r\n\r\n### SeleniumBase/Playwright Login\r\n\r\nAn advanced version of Selenium, **SeleniumBase**, is used for browser automation. It simplifies Selenium operations, making it easier to write tests and automation scripts.\r\n\r\n| Description            | Python        | Node.js                        |\r\n| ------------------------ | --------------------------------------------- | ---------------------------------------------------------- |\r\n| **Open login page**      | `sb.open(login_url)`                          | `await page.goto(login_url, { waitUntil: 'networkidle' })` |\r\n| **Fill username**        | `sb.type('input[name=\"username\"]', username)` | `await page.fill('input[name=\"username\"]', username)`      |\r\n| **Fill password**        | `sb.type('input[name=\"password\"]', password)` | `await page.fill('input[name=\"password\"]', password)`      |\r\n| **Submit form**          | `sb.click('button[type=\"submit\"]')`           | `await page.click('button[type=\"submit\"]')`                |\r\n\r\n\r\n### Session Persistence\r\n\r\nThis example shows how to maintain session state across multiple requests, preserving cookies and authentication tokens after login.\r\n\r\n\r\n| Description             | Python                                                                   | Node.js                                                                                                                 |\r\n| ----------------------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |\r\n| **Create session**      | `session = requests.Session()`                                           | `const jar = new tough.CookieJar();`\u003cbr\u003e`const client = wrapper(axios.create({ jar, withCredentials: true }));` |\r\n| **Authenticate (POST)** | `login_resp = session.post(\"URL\", data=payload)` | `client.post(\"URL\", payload)`                                                                   |\r\n| **Access protected**    | `dash_resp = session.get(\"protected_URL\")`         | `client.get(\"protected_URL\")`                                                                     |\r\n\r\n\r\n### Cookie Handling\r\n\r\nDemonstrates how to handle cookies during login. This is useful for keeping the session alive across requests or saving cookies for future use.\r\n\r\n| Description            | Python                                                    | Node.js                                                                                                 |\r\n| ---------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |\r\n| **Save Cookies**       | `import pickle` \u003cbr\u003e `pickle.dump(session.cookies, f)`    | `const fs = require('fs');` \u003cbr\u003e `fs.writeFileSync(COOKIE_FILE, JSON.stringify(await jar.serialize()))` |\r\n| **Load Cookies**       | `pickle.load(f)`                                          | `const data = fs.readFileSync(COOKIE_FILE);` \u003cbr\u003e `await jar.deserialize(data)`                         |\r\n| **Save Cookies File**  | `pickle.dump(session.cookies, open('cookies.pkl', 'wb'))` | `fs.writeFileSync('cookies.json', JSON.stringify(await jar.serialize()))`                               |\r\n| **Reuse Cookies File** | `load_cookies(session, 'cookies.pkl')`                    | `await loadCookies()`                                                                                   |\r\n\r\n\r\n\r\n## Disclaimer\r\n\r\nThese examples are for **educational purposes** only. Learn more about [the legality of web scraping](\"https://hasdata.com/blog/is-web-scraping-legal\").\r\n\r\n\r\n\r\n\r\n\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasdata%2Flogin-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhasdata%2Flogin-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasdata%2Flogin-examples/lists"}