def parse_detail(self, response): """具体处理获取某一个楼盘的信息""" sel = etree.HTML(response.text) item = LianjialoupanItem() # 楼盘名称 name = sel.xpath( "//div[@class='name-box']/a[@class='clear']/@title")[0] item["name"] = name # 楼盘状态 state = sel.xpath( "//div[@class='name-box']/div[@class='state-div']/span[@class='state']/text()" )[0] item['state'] = state # 楼盘网址 href = sel.xpath("//div[@class='name-box']/a[@class='clear']/@href")[0] item["url"] = self.base_url + href # 楼盘价格 jiage = sel.xpath( "//div[@class='box-left-top']/p[@class='jiage']/span/text()") # item["price"] = jiage if "均价" in jiage: # junjia = sel.xpath("//span[@class='junjia']/text()") # yuan = sel.xpath("span[@class='yuan']/text()") item["price"] = jiage[1] + jiage[2] else: item["price"] = jiage[0] # 物业 try: wuye = sel.xpath("//p[@class='wu-type ']/span/text()") item['wuye'] = wuye[1] except Exception as e: wuye = sel.xpath("//p[@class='wu-type manager']/span/text()") item['wuye'] = wuye[1] print("Error:", e) # 地址 try: where = sel.xpath("//p[@class='where ']/span/@title") item["where"] = where[0] except Exception as e: where = sel.xpath("//p[@class='where manager']/span/@title") item["where"] = where[0] print("Error:", e) yield item
def parse_detail(self, response): """具体处理获取某一个楼盘的信息""" url = response.meta['url'] sel = etree.HTML(response.text) item = LianjialoupanItem() # 楼盘名称 name = sel.xpath( "//div[@class='title-row']/h1[@class='nameShow']/text()")[0] item["name"] = name # 楼盘状态 state = sel.xpath( "//div[@class='title-row']/span[@class='status label']/text()")[0] item['state'] = state # 楼盘网址 item["url"] = url # 楼盘价格 jiage = sel.xpath("//span[@class='num price']/text()") if "已售完" in jiage or "待定" in jiage[0]: item["price"] = jiage[0] else: unit = sel.xpath("//span[@class='unit price']/text()") item["price"] = jiage[0] + unit[0] # 物业 wuye = sel.xpath( "//div[@class='title-row']/span[@class='type label']/text()")[0] item["wuye"] = wuye # 地址 where = sel.xpath("//span[@class='address']/text()")[0] item["where"] = where yield item