Last active
October 7, 2020 09:18
-
-
Save kaicarver/289dcef07d08e24aa29328e02a86f359 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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