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)
相关推荐
cipher4 天前
crawl4ai:AI时代的数据采集利器——从入门到实战
后端·爬虫·python
深蓝电商API4 天前
结构化数据提取:XPath vs CSS 选择器对比
爬虫·python
易辰君4 天前
【Python爬虫实战】正则:中文匹配与贪婪非贪婪模式详解
开发语言·爬虫·python
深蓝电商API4 天前
爬虫增量更新:基于时间戳与哈希去重
爬虫·python
电商API_180079052475 天前
京东商品评论API接口封装的心路历程
服务器·开发语言·爬虫·数据分析·php
袁袁袁袁满5 天前
Haystack与亮数据MCP工具结合实现自动化爬虫
爬虫·python·网络爬虫·数据采集·爬虫实战·视频爬虫·特推爬虫
深蓝电商API5 天前
Redis 作为爬虫去重与任务队列实战
爬虫·python
IP搭子来一个5 天前
爬虫使用代理IP全解析:原理、类型与实战指南
爬虫·网络协议·tcp/ip
iFeng的小屋5 天前
【2026最新xhs爬虫】用Python批量爬取关键词笔记,异步下载高清图片!
笔记·爬虫·python
嫂子的姐夫5 天前
030-扣代码:湖北图书馆登录
爬虫·python·逆向