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)
相关推荐
深蓝电商API2 小时前
大模型 + 爬虫 = ?我用 AI 做了一个自适应反反爬引擎
人工智能·爬虫
༒࿈南林࿈༒3 小时前
国家医保局 API 加密体系逆向全记录——SM2签名 + SM4加解密 + SHA256 头签名
爬虫·大模型应用·mcp·skills
跨境数据猎手3 小时前
复刻Cssbuy跨境淘宝代购集运系统搭建方案
爬虫·架构·系统架构
郑洁文8 小时前
基于网络爬虫的XSS漏洞检测系统的设计与实现
网络·爬虫·网络安全·xss
Super Scraper9 小时前
如何将赋予千问(Qwen Code)网络检索功能:集成MCP服务器
人工智能·爬虫·ai·自动化·千问·mcp·qwen code
SilentSamsara9 小时前
爬虫工程化:Playwright + 反反爬 + 数据清洗管道实战
开发语言·爬虫·python·青少年编程·playwright
专注VB编程开发20年12 小时前
Python爬虫、提取网页内容,免费调用谷歌翻译接口
爬虫·python·信息可视化
Data 实验室12 小时前
TaskPyro爬虫管理平台 v2.3.4:脚本即接口,调度即编排
爬虫
小白学大数据12 小时前
全站链接深度爬取:Python GUI 事件绑定 + 运行时动态过滤实现思路
开发语言·爬虫·python
绘梨衣5471 天前
某爬虫策略的基础skills
爬虫·ai编程