Thank you! Your feedback has been delivered
Thank you! Your feedback has been sent

python scrapy : unable to login on website

I'm trying to login into a website with python script using the sample code given in Scrapy documentation. Here's the modified code:

from scrapy.spider import BaseSpider
from scrapy.http import Request,FormRequest

class LoginSpider(BaseSpider):
    name = 'loginspidername'
    start_urls = ['']

    def parse(self, response):
        return [FormRequest.from_response(response,
                    formdata={'username': 'myname', 'Password': 'mypass'},

    def after_login(self, response):
        # check login succeed before going on
        if "logout" in response.body:
            print 'logged in'
            print 'not logged in'

Also, here's the HTML section, in case required:

<div class="canvas" name="slideblock" id="loginblock" style="display: none;">
    <div class="wrapper">
        <div class="loginFloater">
            <div align="right"><a href="javascript:hideDiv('loginblock');">close(X)</a></div>

            <form method="post" action="login.php">
            <label>Username</label><input class="data" name="username" value="" placeholder="username" type="text"><br>
            <label>Password</label><input class="data" name="password" value="" placeholder="password" type="password"><br>
            <label></label><strong style="display:none ">Wrong Password Try again</strong>
            <label>&nbsp;</label><input type="submit" class="searchButton" value="Login"></form>
            <input type="checkbox" name="rememberme" value="true"> Remember Me<br><br>
            <label>&nbsp;</label><a href="#">Forgot</a> Password?
            Not a member? <a href="javascript:slideDiv('signupblock');">Signup</a> 


The output is always 'not logged in' As simple a code it may seem, it simply isn't logging in. I am unable to think of any possible issue in the code. Any kind of help is appreciated. Thanks for reading.

User Gravatar


Posted Oct 17 2013 5:15 UTC


  • python

1 Replies

it seems that you send Password instead of password

User Gravatar


Posted Oct 19 2013 6:19 UTC

Add a reply

By posting a reply on CodersClan you agree to our Terms & Conditions