pyspider采集例子
2017-07-04 12:33
169 查看
#!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2017-04-04 10:35:52 # Project: retries from pyspider.libs.base_handler import * import re class Handler(BaseHandler): crawl_config = { } def on_start(self): self.crawl('http://www.mofangge.com/', callback=self.index_page) @config(priority=4) def index_page(self, response): for each in response.doc('a[href^="http"]').items(): if re.match("http://www.mofangge.com/qlist/\w+/", each.attr.href, re.U): self.crawl(each.attr.href, callback=self.list_page) @config(priority=3) def list_page(self, response): for each in response.doc('.seoleftul A').items(): self.crawl(each.attr.href, callback=self.detail_page) @config(priority=2) def detail_page(self, response): for each in response.doc('td a').items(): self.crawl(each.attr.href, callback=self.detail_page) return { "url": response.url, "question": response.doc('#q_indexkuai2 table').html(), "answer": response.doc('#q_indexkuai3 table').html(), "subject": response.doc('body > div.content > div.nagetivebanner1 > div > span > a:nth-child(2)').html(), }
相关文章推荐
- pyspider采集例子
- pyspider采集例子
- pyspider采集例子(js)
- 用Asp.Net c#写的采集小例子
- 用Asp.Net c#写的采集小例子
- 用Asp.Net c#写的采集小例子
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
- 用Asp.Net c#写的采集小例子
- php使用curl模拟登录后采集页面的例子
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
- 用Asp.Net c#写的采集小例子
- 采集oracle资源shell脚本例子
- 用PHP的CURL写的一个采集Discuz的例子
- php使用curl模拟登录后采集页面的例子
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
- 采集linux进程资源SHELL例子
- PHP使用CURL_MULTI实现多线程采集的例子
- 用PHP的CURL写的一个采集Discuz的例子
- PHP数据采集curl常用的5个例子
- php使用curl模拟登录后采集页面的例子