使用formrequest登录不起作用

时间:2019-06-21 11:45:23

标签: python scrapy

我正在尝试登录Interpals,我尝试了两种登录方法,但是似乎都无法正常工作,因此csrf令牌已正确提取。我也尝试了log-in-not-working-using-scrapy的答案,但没有解决

import scrapy
from scrapy.http import FormRequest
from scrapy.utils.response import open_in_browser
from scrapy.crawler import CrawlerProcess
class Interpals(scrapy.Spider):
    name = "test"
    start_urls = ['https://www.interpals.net/']
    def parse(self,response):
        csrf = response.xpath('//meta[@name="csrf-token"]/@content').extract_first()
        user = 'USER'
        password = 'PASS'
        data = {
        'username':user,
        'password':password,
        'csrf-token':csrf
        }

        #url = response.urljoin('/app/auth/login')
        response = response.replace(url='https://www.interpals.net/app/account')
        #yield scrapy.FormRequest(url=url,formdata=data,callback=self.parse_after_login)
        yield FormRequest.from_response(response,formdata=data,callback=self.parse_after_login)
    def parse_after_login(self,response):
        open_in_browser(response)

注意:我已经从代码中删除了我的用户,

0 个答案:

没有答案