Scrapy加Selenium爬取简书

爬虫主体:

# -*- coding: utf-8 -*-
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from js_spi.items import ArticleItem


class JsSpider(CrawlSpider):
    name = 'js'
    allowed_domains = ['jianshu.com']
    start_urls = ['https://www.jianshu.com/']

    rules = (
        Rule(LinkExtractor(allow=r'.*/p/[0-9a-z]{12}.*'), callback='parse_page', follow=True),
    )

    def parse_page(self, response):
        title = response.xpath('//section[@class="ouvJEz"]/h1/text()').get()
        author = response.xpath('//span[@class="FxYr8x"]/a/text()').get()
        edit_time = response.xpath('//div[@class="s-dsoj"]//time/text()').get()
        content = response.xpath('//article[@class="_2rhmJa"]').getall()
        fav_count = response.xpath('//span[@class="_1LOh_5"]/text()').get()
        text_type = '|'.join(response.xpath('//a[@class="_3s5t0Q _1OhGeD"]/span/text()').getall())
        item = ArticleItem(title=title,
                           author=author,
                           edit_time=edit_time,
                           content=content,
                           fav_count=fav_count,
                           text_type=text_type)
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值