我试图使用scrapy提交以下表单:
<form id='phpal_form' action='http://www.cecif.com/connexion-a-votre-compte.html' method='post' enctype='application/x-www-form-urlencoded' class='phpal_form f1 login-form'>
<input type="hidden" value="http%3A%2F%2Fwww.cecif.com%2Fmembres-votre-espace.html" name="ref">
<div class="form-line">
<div class="block-label">
<label for="user">Email</label>
</div>
<div class="form-element">
<input name="user" id="email" type="text" value="" maxlength="50" class="text-input">
</div>
</div>
<div class="form-line">
<div class="block-label">
<label for="mdp">Mot de passe</label>
</div>
<div class="form-element">
<input name="mdp" id="mdp" type="password" value="" maxlength="20" class="text-input">
</div>
</div>
<div class="form-button">
<input id="oklogin" type="image" src="/design/defaut/img/ok-button.png" name="cecif_log" value="OK">
</div>
</form>
&#13;
这是我使用过的scrapy课程,但无济于事。
def parse(self, response):
return scrapy.FormRequest.from_response(
response,
formid='phpal_form',
formdata={
'user': 'USERNAME',
'mdp': 'PASSWORD',
'ref': 'http%3A%2F%2Fwww.cecif.com%2Fmembres-votre-espace.html',
'cecif_log' : 'OK'
},
callback=self.after_login
)
def after_login(self, response):
# check login succeed before going on
if "Mon compte CECIF" in response.body:
self.logger.error("Login failed")
print 'ERROR'
return
else:
print "SUCCESS"
#start scrapy crawler
&#13;
上面的代码不起作用,FormRequest的结果是一个空的登录页面,激活了表单提交错误信息。
任何想法都赞赏!非常感谢