Scrapy模拟表单登录

来源:互联网 发布:什么是linux内核 编辑:程序博客网 时间:2024/06/05 23:07

Link

import scrapyclass LoginSpider(scrapy.Spider):    name = 'example.com'    start_urls = ['http://www.example.com/users/login.php']    def parse(self, response):        return scrapy.FormRequest.from_response(            response,            formdata={'username': 'john', 'password': 'secret'},            callback=self.after_login        )    def after_login(self, response):        # check login succeed before going on        # 在Python3中下面的字符串需要改写为b"authentication failed"        if "authentication failed" in response.body:            self.logger.error("Login failed")            return        # continue scraping with authenticated session...
原创粉丝点击