Created
October 25, 2019 10:23
-
-
Save rafikahmed/2d15d3733d37aeef52872367cf189e3b 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
# -*- coding: utf-8 -*- | |
import scrapy | |
import hashlib | |
from scrapy.http import FormRequest | |
class ItrlogSpider(scrapy.Spider): | |
name = 'itrlog' | |
start_urls = ['http://itr.lacecal.es/page/index.php?s=login'] | |
def parse(self, response): | |
token = response.xpath('//input[@name="token"]/@value').extract_first() | |
#Website algorithm for encrypting the password | |
# you start by encrypting the password to sha1 | |
# you add the token to the encrypted password | |
# then you encrypt again password+token | |
#put your password in here, replace 'mypassword' | |
password_encrypted = hashlib.sha1(b"mypassword").hexdigest() | |
password_token = f"{password_encrypted}{token}" | |
password_token_encrypted = hashlib.sha1(str.encode(password_token)).hexdigest() | |
yield FormRequest.from_response(response=response, formxpath ="//form[@id='form_login']",formdata={ | |
'token':token, | |
'password':password_token_encrypted, | |
'user':'myuser', #username | |
'dummy':'**********', #this must be left like this | |
'login':'Login', | |
},callback=self.after_login) | |
def after_login(self,response): | |
yield { | |
'token':response.xpath('//input[@name="token"]/@value').extract_first(), | |
'palabra':response.xpath('//input[@name="password"]/@value').extract_first(), | |
'Dato': response.xpath('//a[@class="active"]/text()').extract_first() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment