想要爬取爱卡汽车的每个汽车的口碑,但是在翻页问题总是进不去,无论是用chorme还是自带的css selector helper抓取到的CSS PATH都无法翻页,请求帮助,代码如下
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2017-03-21 12:57:03
# Project: test03
import re
from pyspider.libs.base_handler import *
class Handler(BaseHandler):
crawl_config = {
}
@every(minutes=24 * 60)
def on_start(self):
self.crawl('http://newcar.xcar.com.cn/price/', callback=self.index_page)
@config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('a[href^="http"]').items():
if re.match("http://newcar.xcar.com.cn/\d", each.attr.href, re.U):
self.crawl(each.attr.href, callback=self.list_page)
def list_page(self, response):
for each in response.doc('body > p.demio_wp > p > ul > li:nth-child(6) > a').items():
self.crawl(each.attr.href, callback=self.list_page1)
def list_page1(self, response):
for each in response.doc('.review_gml_tit > .more').items():
self.crawl(each.attr.href, callback=self.detail_page)
#翻页,问题出在下面这里
for each in response.doc('body > p.review_main > p.review_left > p > p.review_comments > p.review_comments_dl > p.pagers > a:nth-child(2)').items():
self.crawl(each.attr.href, callback=self.list_page1)
@config(priority=2)
def detail_page(self, response):
return {
"branch":response.doc('#nav_ps > em > a').text(),
"text":response.doc('body > p.review_main > p.review_left > p > p.review_comments > p.review_comments_dl > dl > dd').text(),
}
Komen dimuatkan menggunakan javascript.