JiwuspiderSpider.py
# -*- coding: utf-8 -*-
from scrapy import Spider,Request
import re
from jiwu.items import JiwuItem
class JiwuspiderSpider(Spider):
name = "jiwuspider"
allowed_domains = ["wlmq.jiwu.com"]
start_urls = ['http://wlmq.jiwu.com/loupan']
def parse(self,response):
"""
解析每一页房屋的list
:param response:
:return:
"""
for url in response.xpath('//a[@class="index_scale"]/@href').extract():
yield Request(url,self.parse_html) # 取list集合中的url 调用详情解析方法
# 如果下一页属性还存在,则把下一页的url获取出来
nextpage = response.xpath('//a[@class="tg-rownum-next index-icon"]/@href').extract_first()
#判断是否为空
if nextpage:
yield Request(nextpage,self.parse) #回调自己继续解析
def parse_html(self,response):
"""
解析每一个房产信息的详情页面,生成item
:param response:
:return:
"""
pattern = re.compile('