您的位置:首页 > 编程语言 > Python开发

python 爬虫实战(三)使用pyspider爬取虎嗅新闻

2018-03-12 15:29 561 查看
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-03-02 23:14:26
# Project: huxiu

from pyspider.libs.base_handler import *

class Handler(BaseHandler):
crawl_config = {
}

@every(minutes=24 * 60)
def on_start(self):
self.crawl('https://www.huxiu.com/channel/105.html', callback=self.index_page,validate_cert=False)

@config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('.mod-b.mod-art.clearfix h2 > a').items():
self.crawl(each.attr.href, callback=self.detail_page,validate_cert=False,fetch_type='js')

@config(priority=2)
def detail_page(self, response):
return {
"url": response.url,
"title": response.doc('title').text()+' ',
"detail":response.doc('.article-content-wrap > p').text()
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: