scrapy爬虫实战(部分源代码)

items.py

python 复制代码
# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy


class Sss1Item(scrapy.Item):
    # define the fields for your item here like:
    name = scrapy.Field()

spider_title.py

python 复制代码
import scrapy
from sss1.items import Sss1Item
class SpiderTitleSpider(scrapy.Spider):
    name = "spider_title"
    allowed_domains = ["www.zongheng.com"]
    start_urls = ["https://read.zongheng.com/chapter/1215341/68208370.html"]

    def parse(self, response):
        item=Sss1Item()
        f=open('我有一剑.txt','a',encoding='utf8')
        titles=response.xpath('//*[@id="Jcontent"]/div/div[1]/div[2]/text()').extract()
        for asd in titles:
            f.write(asd+"\n")

        names=[each.extract() for each in response.xpath('//*[@id="Jcontent"]/div/div[4]/p[3]/span[1]/text()')]
        # for asd in names:
        #     f.write(asd+"\n")
        item['name']=names
        yield item
        next=response.xpath('//*[@id="page_reader"]/div[3]/div[1]/div[3]/div[1]/a[3]/@href').get()
        next=next.replace("?","")
        print('----------------------------------------------------------')
        print(next)
        if next:
            yield scrapy.Request(url=next,callback=self.parse)
相关推荐
Caco_D3 天前
一行代码抓遍全网 20 个热榜!Aneiang.Pa 4.0 发布 — 极简 .NET 爬虫库
爬虫·.net
太岁又沐风8 天前
复现并修掉ART hook框架 Pine 调用原方法时的偶发 SIGSEGV
爬虫
隔窗听雨眠8 天前
大模型加爬虫上篇:技术融合与架构革新
爬虫·架构
Super Scraper9 天前
如何批量抓取 TikTok 数据而不被封锁?完整指南
爬虫·ai·自动化·抖音·tiktok·ai agent
深蓝电商API9 天前
自动化录屏 + 截图:打造爬虫调试的上帝视角
爬虫
tang777899 天前
市场调研自动化采集架构:基于住宅IP轮换的APP数据抓取与反风控方案
爬虫·动态代理ip·爬虫代理ip·爬虫动态ip·住宅代理ip·动态住宅ip
数据知道9 天前
指纹浏览器环境的导入、导出、快照与云端同步机制
爬虫·数据采集·指纹浏览器
星川皆无恙9 天前
大数据k-means聚类算法:基于k-means聚类算法+NLP微博舆情数据爬虫可视化分析推荐系统(新版)
大数据·人工智能·爬虫·算法·机器学习·自然语言处理·kmeans
小二·9 天前
Rust 爬虫与数据处理实战:大规模并发抓取 + 流式处理
开发语言·爬虫·rust