How to do it

Supporting basic auth in Scrapy is straightforward. To get this to work for a spider and a given site the spider is crawling, simply define the http_user, http_pass, and name fields in your scraper. The following demonstrates:

class SomeIntranetSiteSpider(CrawlSpider):
    http_user = 'someuser'
    http_pass = 'somepass'
    name = 'intranet.example.com'
    # .. rest of the spider code omitted ...

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.