我尝试登录某个网站,但似乎他们不使用表单来显示登录对话框。因此,当使用FormRequest时,我收到了错误
raise ValueError("No <form> element found in %s" % response)
那么在这种情况下如何使用scrapy登录?
我尝试在此网站中找到一个表单元素(使用带有xpath //表单的chrome devtool)但结果为零
它的登录元素是
<div class="loginModalBody">
<div class="coverLoginModal">
<p class="loginModalTitle">Login </p>
<div class=""><p class="login-msg"></p></div>
<!-- Email -->
<div class="loginCoverInputText">
<input class="loginInputText" id="email-login" role="presentation" autocomplete="off" type="email" name="loginEmail" placeholder="E-mail">
<span class="loginNameInputText">E-mail</span>
<span class="loginLineInputText"></span>
<!-- Error email -->
<div class="dontEnterEmail loginErrorInput"><p class="loginError">Vui lòng nhập email<span class="loginIconError"></span></p></div>
<div class="loginEmailInvalid loginErrorInput"><p class="loginError">Invalid email<span class="loginIconError"></span></p></div>
</div>
<!-- Password -->
<div class="loginCoverInputText">
<input class="loginInputText" id="password-login" autocomplete="new-password" type="password" name="loginPassword" placeholder="Password">
<span class="loginNameInputText">Password</span>
<span class="loginLineInputText"></span>
<!-- Error password -->
<div class="dontEnterPassword loginErrorInput"><p class="loginError">Enter password<span class="loginIconError"></span></p></div>
</div>
<!-- Remember password -->
<label class="loginRememberPassword" id="login-remember-pass" for="loginRememberPassword"><input id="loginRememberPassword" type="checkbox" name="loginRememberPassword"><span></span>Ghi nhớ mật khẩu</label>
<p class="loginForgotPassword forgot-password"> <a href="javascript:void(0)" data-dismiss="modal"><span></span>forgot pass</a></p>
<button class="loginButtonSubmit btn-login" id="btn-login-system" type="button">Login</button>
<p class="loginDontAccount">Do not have account? <a class="not-account" href="javascript:void(0)" data-dismiss="modal" data-toggle="modal" data-target="#modal-signup-system">Register!</a></p>
<p class="loginOr">Or</p>
<button type="button" class="loginByGoogle" onclick="open_login_g()">Login with Google</button>
<button type="button" class="loginByFacebook" onclick="open_login_f()">Login with Facebook</button>
</div>
</div>
我使用的代码是
class Spider(scrapy.Spider):
name = "card"
start_urls = ["https://website/auth/signin"]
login_user = "foo"
login_pass = "bar"
def parse(self, response):
'''Parse login page'''
open_in_browser(response)
return FormRequest.from_response(
response,
formdata={
'email':"username",
'password': "pass"
},
callback=self.parse_home
)
def parse_home(self, response):
open_in_browser(response)
print response
答案 0 :(得分:2)