PINGDOM_CHECK

#ExtractSummit2026 The world's largest web scraping conference returns. Austin Oct 7–8 · Dublin Nov 10–11.

Register now
Data Services
Pricing
Login
Try Zyte APIContact Sales
  • Unblocking and Extraction

    Zyte API

    The ultimate API for web scraping. Avoid website bans and access a headless browser or AI Parsing

    Ban Handling

    Headless Browser

    AI Extraction

    SERP

    Enterprise

    DocumentationSupport

    Hosting and Deployment

    Scrapy Cloud

    Run, monitor, and control your Scrapy spiders however you want to.

    Coding Agent Add-Ons

    Agentic Web Data

    Plugins that give coding agents the context to build production Scrapy projects. Starts with Claude Code.

  • Data Services
  • Pricing
  • Browse

    • BlogArticles, podcasts, videos
    • Case studiesCustomer outcomes
    • White papersIn-depth reports
    • EventsConferences, webinars, recordings

    Subscribe

    • NewsletterSwiftly delivered
    • Discord communityExtract Data community
  • Product and E-commerce

    From e-commerce and online marketplaces

    Data for AI

    Collect and structure web data to feed AI

    Job Posting

    From job boards and recruitment websites

    Real Estate

    From Listings portals and specialist websites

    News and Article

    From online publishers and news websites

    Search

    Search engine results page data (SERP)

    Social Media

    From social media platforms online

  • Meet Zyte

    Our story, people and values

    Contact us

    Get in touch

    Support

    Knowledge base and raise support tickets

    Terms and Policies

    Accept our terms and policies

    Open Source

    Our open source projects and contributions

    Web Data Compliance

    Guidelines and resources for compliant web data collection

    Join the team building the future of web data
    We're Hiring
    Trust Center
    Security, compliance & certifications
Login
Try Zyte APIContact Sales

Zyte Developers

Coding tools & hacks straight to your inbox

Become part of the community and receive a bi-weekly dosage of all things code.

Join us
    • Zyte Data
    • News & Articles
    • Search
    • Social Media
    • Product
    • Data for AI
    • Job Posting
    • Real Estate
    • Zyte API - Ban Handling
    • Zyte API - Headless Browser
    • Zyte API - AI Extraction
    • Web Scraping Copilot
    • Zyte API Enterprise
    • Scrapy Cloud
    • Solution Overview
    • Blog
    • Webinars
    • Case Studies
    • White Papers
    • Documentation
    • Web Scraping Maturity Self-Assesment
    • Web Data compliance
    • Meet Zyte
    • Jobs
    • Terms and Policies
    • Trust Center
    • Support
    • Contact us
    • Pricing
    • Do not sell
    • Cookie settings
    • Sign up
    • Talk to us
    • Cost estimator
All articles
AI-assisted data extraction28, 28 articles
Data gathering for AI6, 6 articles
Large Language Models (LLMs)24, 24 articles
Tool-assisted coding3, 3 articles
Developer interest143, 143 articles
Integration13, 13 articles
Open-source96, 96 articles
Scraping practice59, 59 articles
Scraping strategy46, 46 articles
Anti-ban35, 35 articles
Traffic6, 6 articles
Web data application25, 25 articles
Web data collection358, 358 articles
Web data collection ethics3, 3 articles
Web data collection legality16, 16 articles
Web scraping APIs63, 63 articles
Zyte API59, 59 articles
Scrapy48, 48 articles
Scrapy Cloud10, 10 articles
Web Scraping Copilot12, 12 articles
AI & Machine Learning1, 1 articles
Automotive2, 2 articles
E-commerce & retail26, 26 articles
Entertainment & Streaming2, 2 articles
Financial Services8, 8 articles
Government2, 2 articles
Market Research & Intelligence3, 3 articles
Media & publishing8, 8 articles
Real Estate2, 2 articles
Recruitment & HR3, 3 articles
Transportation & Logistics2, 2 articles
Travel & hospitality2, 2 articles
Extract Summit25, 25 articles
PyCon1, 1 articles

Appearance

Discord Community
BlogProduct UpdateHow To Fill Login Forms Automatically
ArticleTutorial / How-toProduct Update

How To Fill Login Forms Automatically

We often have to write spiders that need to fill login forms to sites. Our customers provide us with the site, username and password, and we do the rest.

P

Pablo Hoffman

3 min read · October 26, 2012

How to fill login forms automatically

We often have to write spiders that need to login to sites, in order to scrape data from them. Our customers provide us with the site, username and password, and we do the rest.

The classic way to approach this problem is:

  1. launch a browser, go to site and search for the login page
  2. inspect the source code of the page to find out:
    1. which one is the login form (a page can have many forms, but usually one of them is the login form)
    2. which are the field names used for username and password (these could vary a lot)
    3. if there are other fields that must be submitted (like an authentication token)
  3. write the Scrapy spider to replicate the form submission using FormRequest (here is an example)

Being fans of automation, we figured we could write some code to automate point 2 (which is actually the most time-consuming) and the result is loginform, a library to automatically fill login forms given the login page, username and password.

Here is the code of a simple spider that would use loginform to login to sites automatically:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

from scrapy.spider import BaseSpider

from scrapy.http import FormRequest

from loginform import fill_login_form

class LoginSpider(BaseSpider):

start_urls = ["http://github.com/login"\]

login_user = "foo"

login_pass = "bar"

def parse(self, response):

args, url, method = fill_login_form(response.url, response.body, self.login_user, self.login_pass)

return FormRequest(url, method=method, formdata=args, callback=self.after_login)

def after_login(self, response):

# you are logged in here

from scrapy.spider import BaseSpider from scrapy.http import FormRequest from loginform import fill_login_form class LoginSpider(BaseSpider): start_urls = ["http://github.com/login"\] login_user = "foo" login_pass = "bar" def parse(self, response): args, url, method = fill_login_form(response.url, response.body, self.login_user, self.login_pass) return FormRequest(url, method=method, formdata=args, callback=self.after_login) def after_login(self, response): # you are logged in here

1from scrapy.spider import BaseSpider
2from scrapy.http import FormRequest
3from loginform import fill\_login\_form
4
5class LoginSpider(BaseSpider):
6
7    start\_urls = \["http://github.com/login"\]
8    login\_user = "foo"
9    login\_pass = "bar"
10
11    def parse(self, response):
12        args, url, method = fill\_login\_form(response.url, response.body, self.login\_user, self.login\_pass)
13        return FormRequest(url, method=method, formdata=args, callback=self.after\_login)
14
15    def after\_login(self, response):
16        # you are logged in here
Copy

In addition to being open source, loginform code is very simple and easy to hack (check the README on Github for more details). It also contains a collection of HTML samples to keep the library well-tested, and a convenient tool to manage them. Even with the simple code so far, we have seen accuracy rates of 95% in our tests. We encourage everyone with similar needs to give it a try, provide feedback and contribute patches.

We contributed this project to the Scrapy group to better encourage community adoption and contributions. Like w3lib and scrapely, loginform is completely decoupled and not dependent on the Scrapy crawling framework.

Try Zyte API

Build your first scraper in minutes

Free trial, no credit card. From a single request to production in an afternoon.

Get started
Product Update
P

Pablo Hoffman

More from this author

Follow

Get the latest

Zyte and the data web in your inbox — or wherever you already are.

Subscribe

Or follow elsewhere

Continue reading

Play Before You Scrape: Explore Zyte API Settings with Playground
Product Update

Play Before You Scrape: Explore Zyte API Settings with Playground

Discover the best way to configure your scrapers using Zyte API Playground

Cleber Alexandre·10 Mins·February 10, 2025
New in Zyte: Scroll Control, Lower Costs, and More
Product Update

New in Zyte: Scroll Control, Lower Costs, and More

As the web continues to evolve, Zyte API is evolving right alongside it—adding powerful new features and refinements designed to make data extraction smarter, faster, and more adaptable than ever.

Daniel Cave·5 min·June 27, 2025
From products to SERPs: AI scraping now does it all
Product Update

From products to SERPs: AI scraping now does it all

Scale data extraction with Zyte’s composite AI, combining accuracy, flexibility, and cost-efficiency in one powerful scraping solution, now available for the most common data types.

Cleber Alexandre·10 mins·April 3, 2025

The Community · Newsletter

The best of Zyte and the data web, in your inbox.

One curated edition — new articles, product updates, and the stories shaping the data web. No noise.

G2.com

Capterra.com

Proxyway.com

EWDCI logoMost loved workplace certificateZyte rewardISO 27001 iconG2 rewardG2 rewardG2 reward

© Zyte Group Limited 2026