http://house.njhouse.com.cn/r...
网站的翻页链接都显示成一个 # ,还能用crawl spider吗。
如果能用的话这个网站的rules该怎么写。
我写的这个不行额
rules = [
Rule(LinkExtractor(allow=('/rent/houselist/p-d+',)),callback='parse_item', follow=True),
]
下面是我的爬虫主要代码,该怎么修改。
class ListSpider(CrawlSpider):
# 爬虫名称
name = "nanjingtenement"
# 允许域名
allowed_domains = ["njhouse.com.cn"]
# 开始URL
start_urls = ['http://house.njhouse.com.cn/rent/houselist/p-1'
]
rules = [
Rule(LinkExtractor(allow=(r'/rent/houselist/p-'+ '\d+' ,)),callback='parse_item', follow=True),
]
# 解析内容函数
def parse_item(self, response):
for sel in response.xpath('//div[@class="list_main_lists"]/ul/li[not(@id)]'):
item = NanjingItem()
link = sel.xpath('a/@href')[0].extract()
item['link'] = link
pageno=response.selector.xpath('//div[@class="pagination-container"]/a[@class="active btn-active-filter"]/text()')[0].extract()
item['pageno'] = pageno
listingchannel=sel.xpath('div/p/text()')[0].extract()
item['listingchannel'] = listingchannel
yield item
取data-index就好了,分页url是http://house.njhouse.com.cn/r...
只需用把'http://house.njhouse.com.cn/r...'拼接上页码就可以了。
或者
观察有多少页码直接循环拼接出所有分页的url就可以。