Skip to content

Instantly share code, notes, and snippets.

@kaicarver
Last active October 7, 2020 09:18
Show Gist options
  • Select an option

  • Save kaicarver/289dcef07d08e24aa29328e02a86f359 to your computer and use it in GitHub Desktop.

Select an option

Save kaicarver/289dcef07d08e24aa29328e02a86f359 to your computer and use it in GitHub Desktop.
import scrapy
from scrapy.http import FormRequest
class LoginSpider(scrapy.Spider):
name = 'login'
allowed_domains = ['quotes.toscrape.com']
start_urls = ['http://quotes.toscrape.com/login']
def parse(self, response):
csrf_token = response.xpath(
'//*[@name="csrf_token"]/@value').get()
yield FormRequest.from_response(response,
formdata={
'csrf_token': csrf_token,
'user': 'user', 'pass': 'pass'},
callback=self.parse_after_login)
def parse_after_login(self, response):
print("logged in!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment