pyspider爬取豆瓣延禧攻略短评和回应

4 篇文章 0 订阅
2 篇文章 0 订阅

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-08-30 15:08:10
# Project: yanxigonglve_douban

from pyspider.libs.base_handler import *
from lxml import etree


class Handler(BaseHandler):
    crawl_config = {
    }

    @every(minutes=24 * 60)
    def on_start(self):
        self.crawl('https://movie.douban.com/subject/26999852/discussion/', callback=self.index_page,validate_cert=False)

    @config(age=10 * 24 * 60 * 60)
    def index_page(self, response):
        # 利用xpath获取短评的链接,主要目的是为了得到详情页面的回应
        s = etree.HTML(response.text)
        href = s.xpath('//*[@id="posts-table"]/tr/td[1]/a/@href')
        print(href)
        for i in href:
            self.crawl(i, callback=self.detail_page,validate_cert=False)
        # 获取下一页的链接
        next = response.doc('.next > a').attr.href
        self.crawl(next, callback=self.index_page,validate_cert=False)
        
    @config(priority=2)
    def detail_page(self, response):
        return {
            "url": response.url,
            "title": response.doc('title').text(),
            'content': response.doc('.post .comment-item').text()
        }
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值