python - pyspider翻页问题?
问题描述
想要爬取爱卡汽车的每个汽车的口碑,但是在翻页问题总是进不去,无论是用chorme还是自带的css selector helper抓取到的CSS PATH都无法翻页,请求帮助,代码如下
#!/usr/bin/env python# -*- encoding: utf-8 -*-# Created on 2017-03-21 12:57:03# Project: test03import refrom 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(), }
问题解答
回答1:评论是 javascript 加载的。
相关文章:
1. javascript - jQuery post()方法,里面的请求串可以转换为GBK编码么?可以的话怎样转换?2. python3.x - python 中的maketrans在utf-8文件中该怎么使用3. javascript - 一排三个框,各个框的间距是15px,距离外面的白框间距也是15px,这个css怎么写?4. javascript - nodejs调用qiniu的第三方资源抓取,返回401 bad token,为什么5. html5 - vue-cli 装好了 新建项目的好了,找不到项目是怎么回事?6. javascript - immutable配合react提升性能?7. mysql - C#连接数据库时一直这一句出问题int i = cmd.ExecuteNonQuery();8. django - python 2层文件夹导入9. python - 用urllib抓取网页上的下载链接,目标文件是xls形式,但发现抓下来的xls是空表,里面只有一句报错信息,求帮助。10. javascript - vue 手机端项目在进入主页后 在进入子页面,直接按返回出现空白情况

网公网安备