scrapy 爬取 arxiv.org 论文

本文介绍使用Scrapy框架抓取arXiv.org网站论文信息的过程,包括配置Item、Pipeline及Spider类,实现了从网页中提取论文标题、作者和主题等数据,并将结果保存为JSON文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

和同学想要建立一个检索 arxiv.org 论文的网站,这是一个 demo
Github地址:https://github.com/Joovo/Arxiv

鸽了好久把博客补了, scrapy 的操作:

  • scrapy shell 检验 xpath 正确性
  • reponse.xpath().extract() 转换为字符串列表
  • str.strip()处理数据
  • 获取 xpath 的子节点的所有 text

arxiv.org 本身是通过构造 url 来爬取比较简单,通过构造年月的时间戳和页面展示数据的条数。

python3 -m scrapy startproject Arxiv
cd Arxiv
# quick start a simple spider
scrapy genspider arxiv arxiv.org

# how to crawl 
scrapy crawl arxiv

有了基本框架后,修改items.py

# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html
import scrapy


class ArxivItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    title=scrapy.Field()
    authors=scrapy.Field()
    comments=scrapy.Field()
    subjects=scrapy.Field()

修改pipelines.py,用于下载

# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import json


class ArxivPipeline(object):
    def __init__(self):
        self.file = open('./items.json', 'a+')

    def process_item(self, item, spider):
        content = 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值