无法登录

2024-04-27 04:53:49 发布

您现在位置:Python中文网/ 问答频道 /正文

i have check formdata also我无法登录到该网站。网站不包含任何令牌或隐藏变量。 请给出正确的例子或告诉我如何解决这个错误。 在post调用之后,它返回相同的登录页面html。 我试过用错误的用户名和密码还是一样的回复。在

import scrapy

class ExampleSpider(scrapy.Spider):
    name = 'example'
    start_urls = ['http://schedule.amacotton.com/']
    LOGIN_URL = 'http://schedule.amacotton.com/login.php'
    URL = 'http://schedule.amacotton.com/transportation.php'

    def parse(self, response):
        my_data = {'user': 'abc', 'pass': 'abc', 'plant': '1','login':'Login'}
        yield scrapy.FormRequest.from_response(
            response= response,
            formdata= my_data,
            callback=self.scrap_page,
        )

    def scrap_page(self, response):
        print response.body

输出:

^{pr2}$

Tags: selfcomhttpurl网站responsemydef
1条回答
网友
1楼 · 发布于 2024-04-27 04:53:49

您确定登录没有成功吗?我刚刚检查了那个页面和无效登录页面看起来和您提供的输出完全不同-那里没有表单,只有无效的登录信息。也许成功登录后,网站不会将用户重定向到任何地方?在

我认为你应该在登录后转到你想删除的网址:

import scrapy

class ExampleSpider(scrapy.Spider):
    name = 'example'
    start_urls = ['http://schedule.amacotton.com/']
    LOGIN_URL = 'http://schedule.amacotton.com/login.php'
    URL = 'http://schedule.amacotton.com/transportation.php'

    def parse(self, response):
        my_data = {'user': 'abc', 'pass': 'abc', 'plant': '1','login':'Login'}
        yield scrapy.FormRequest.from_response(
            response= response,
            formdata= my_data,
            callback=self.open_page,
        )

    def open_page(self, response):
        yield scrapy.Request(
            url=self.URL,
            callback=self.scrap_page
        )

    def scrap_page(self, response):
        print response.body

相关问题 更多 >