The following is the html of the page categories
<p id="a144e40e-56c4-4984-b404-1a0230194b42" class="house-item clearfix house-item-curr">
<p class="item-photo fl">
<a href="/zufang/shbs12427828.html" target="_blank">
<img class="lazy" src="//imgsh.centanet.com/ctpostimage/a4/d5/4e4da3a2496299b2b26243565af6_220x165.jpg" src="//imgsh.centanet.com/ctpostimage/a4/d5/4e4da3a2496299b2b26243565af6_220x165.jpg" alt="采菊苑租房2800元/月" title="采菊苑租房2800元/月" style="display: inline-block;"></a>
</p>
<p class="item-info fl">
<h4 class="house-title">
<a href="/zufang/shbs12427828.html" title="采菊苑,77平两房出租,毛坯3千,好谈价!" target="_blank" class="cBlueB">采菊苑,77平两房出租,毛坯3千,好谈价!</a>
</h4>
<p class="f14 f000 mb_10">
<a href="/xiaoqu/xq-pedpwawows/" class="f000 mr_10" target="_blank" title="采菊苑二手房">采菊苑</a><span class="f000 mr_10">2室2厅</span><span class="f000">77平</span>
</p>
<p class="f7b mb_10">
南北<em class="mrl_6">|</em>高层<em class="mrl_6">|</em>毛坯<em class="mrl_6">|</em>2008年<em class="mrl_6">|</em>整租
</p>
<p class="f7b mb_15">
宝山-顾村 菊联路68弄
<a style="cursor: pointer" href="javascript:void(0)" value="/page/v1/common/maputil.aspx?x=121.372168&y=31.354713" class=" icons_map jsmapicon "></a>
</p>
</p>
<p class="item-pricearea fr">
<p class="price-nub cRed">2800元/月</p>
<p class="f14 f000 mb_15 fsm"> </p>
</p>
<p class="clear"></p>
</p>
I use xpath to extract text. My code is
class itcast(scrapy.Spider):
name = 'SH'
allowd_domains = ["http://sh.centanet.com/"]
start_urls = ["http://sh.centanet.com/zufang/p2/"]
def parse(self,response):
list = response.xpath("//p[@class='//p[@class='ouse-item clearfix house-item-curr']")
for i in list:
name = i.xpath("//a[@class='cBlueB'.text()]")
print name[0]
I can find this category
The error reported is in the line for i in list:
name =f.xpath(), the text cannot be extracted.
The execution code cannot be found. Please help me find out what is wrong with me. I have tried similar things many times. I have no choice but to ask questions. I hope you can answer them. Thank you!
代言2017-06-14 10:53:10
def parse(response):
list = response.xpath("//p[@class='house-item clearfix house-item-curr']")
for i in list:
name = i.xpath("//a[@class='cBlueB']")
print name[0].text
Maybe that’s what you mean?
習慣沉默2017-06-14 10:53:10
name = i.xpath("//a[@class='cBlueB'.text()]") is wrong. How can text be placed inside []