python - scrapy xpath 頁(yè)面解析找不到
問(wèn)題描述
下面是頁(yè)面大類(lèi)的html
<p class='house-item clearfix house-item-curr'><p class='item-photo fl'> <a href='http://www.b3g6.com/zufang/shbs12427828.html' target='_blank'><img src='https://imgsh.centanet.com/ctpostimage/a4/d5/4e4da3a2496299b2b26243565af6_220x165.jpg' src='https://imgsh.centanet.com/ctpostimage/a4/d5/4e4da3a2496299b2b26243565af6_220x165.jpg' alt='采菊苑租房2800元/月' style='display: inline-block;'></a></p><p class='item-info fl'> <h4 class='house-title'><a href='http://www.b3g6.com/zufang/shbs12427828.html' target='_blank' class='cBlueB'>采菊苑,77平兩房出租,毛坯3千,好談價(jià)!</a> </h4> <p class='f14 f000 mb_10'><a href='http://www.b3g6.com/xiaoqu/xq-pedpwawows/' target='_blank'>采菊苑</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'>寶山-顧村 菊聯(lián)路68弄<a 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>
我用xpath提取text 我的代碼是
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]
我可以找到這個(gè)大類(lèi)報(bào)錯(cuò)是在 for i in list:name =f.xpath()這行,text提取不到。執(zhí)行代碼找不到,幫我看看我是哪里不對(duì),類(lèi)似的我也試過(guò)好多次,沒(méi)辦法了,只能提問(wèn)了希望能回答下 謝謝!
問(wèn)題解答
回答1: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
也許你是這個(gè)意思?
回答2:name = i.xpath('//a[@class=’cBlueB’.text()]')這種寫(xiě)法是錯(cuò)誤的,text怎么能放在[]里面呢
相關(guān)文章:
1. mac里的docker如何命令行開(kāi)啟呢?2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?4. 關(guān)于docker下的nginx壓力測(cè)試5. docker容器呢SSH為什么連不通呢?6. nignx - docker內(nèi)nginx 80端口被占用7. 如何解決Centos下Docker服務(wù)啟動(dòng)無(wú)響應(yīng),且輸入docker命令無(wú)響應(yīng)?8. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????9. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。10. docker start -a dockername 老是卡住,什么情況?

網(wǎng)公網(wǎng)安備