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)
相关推荐
胡耀超3 小时前
Web Crawling 网络爬虫全景:技术体系、反爬对抗与全链路成本分析
前端·爬虫·python·网络爬虫·数据采集·逆向工程·反爬虫
itjinyin3 小时前
初级爬虫实战——巴黎圣母院新闻
爬虫
vx_biyesheji00016 小时前
计算机毕业设计:Python多源新闻数据智能舆情挖掘平台 Flask框架 爬虫 SnowNLP ARIMA 可视化 数据分析 大数据(建议收藏)✅
爬虫·python·机器学习·数据分析·django·flask·课程设计
j_xxx404_7 小时前
爬虫对抗:ZLibrary反爬机制实战分析 (三) - 突破高频访问限制与TLS指纹(JA3)风控
爬虫
16Miku7 小时前
Mapping-Skill:把 AI/ML 人才搜索、作者挖掘与个性化触达整合成一条工作流
爬虫·ai·飞书·agent·skill·openclaw·龙虾
j_xxx404_8 小时前
爬虫对抗:ZLibrary反爬机制实战分析 (一) - 撕裂前端JS混淆与环境检测伪装
爬虫
小邓睡不饱耶9 小时前
东方财富网股票数据爬取实战:从接口分析到数据存储
开发语言·爬虫·python·网络爬虫
Pioneer000019 小时前
爬虫对抗:ZLibrary反爬机制实战分析
爬虫
j_xxx404_10 小时前
爬虫对抗:ZLibrary反爬机制实战分析 (二) - 破解动态请求签名与参数加密
爬虫
vx_biyesheji000110 小时前
计算机毕业设计:Python全栈图书数据挖掘与可视化看板 Django框架 爬虫 当当图书 Pandas 可视化 大数据 大模型 书籍(建议收藏)✅
爬虫·python·机器学习·数据挖掘·django·毕业设计·课程设计