提取信息这是我的代码:Scrapy:从特定的div
def parse(self, response):
return scrapy.FormRequest.from_response(
response,
formdata={'uuid': 'user', 'password': 'cons'},
callback=self.after_login
)
def after_login(self, response):
# check login succeed before going on
if "authentication failed" in response.body:
self.log("Login failed", level=log.ERROR)
else:
self.log('LOGGED')
sel = Selector(response)
sel.xpath("//div[@class='amount cSpringGreen']/text()").extract()
但是,当我执行它没有出现。它应该工作的方式是在网站上显示该信息后登录。 html代码是这样的。
<h1 class="hide2"></h1>
<div id="vodaint-local" class="wrapper rhomb">
<div class="spring">
<script type="text/javascript">
<div class="mod mod-selectsizeheader vodaint-local">
<div id="mivf" class="content">
<div id="navigation-breadcrumb" class="belt">
<div class="belt">
<div class="miVFR">
<div class="mainMiVF cf">
<div class="headerMiVF cf">
<div class="bodyMiVF cf">
<div class="mainNav" style="height: auto;">
<div class="mainContent withHeader" style="height: 585px;">
<style>
<div id="contentSpinner" style="margin-bottom: 432px; display: none;">
<script>
<section>
<script type="text/javascript">
<div class="mainContentContainer home">
<div class="headerBanner">
<script type="text/javascript">
<div class="lineContainer ">
<h6 class="topHeading prepago"> </h6>
<div class="columnGroup cf">
<div class="column newPromo">
<div class="columnContent">
<p class="cTitle"> Tu saldo</p>
--THIS IS THE INFO I WANT TO SHOW--
<div class="amount cSpringGreen">
0,
<span> 96</span>
€
</div>
谢谢!
编辑:在这个pastebin中你可以找到整个HTML文件http://pastebin.com/B2HpACCw我想登录后显示的东西是“0'96”,谢谢!
的HTML是有点怪异。有很多没有关闭的'div'和'script'。甚至还有一个可疑的'style'元素。 – dreyescat 2014-11-22 19:15:18
我不确定我是否明白确切的问题 - 是否有任何“'after_login”方法中的消息被打印?究竟是什么问题:蜘蛛没有在网站上登录,或者是数据没有被抓取? – elias 2014-11-22 19:29:37
登录完美地工作,它显示LOGGED在屏幕上,问题是之后,它不显示任何东西。 – AngelaBR 2014-11-23 20:18:20