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)
相关推荐
计算机徐师兄16 小时前
Python基于Flask的豆瓣电影数据分析可视化系统(附源码,文档说明)
爬虫·python·flask·豆瓣电影·豆瓣电影数据分析可视化系统·豆瓣电影数据分析·python豆瓣电影数据分析
大数据学习爱好者18 小时前
基于flask+vue的租房信息可视化系统
大数据·开发语言·爬虫·python·信息可视化
大叔是90后大叔18 小时前
scrapy在pipelines中获取项目根目录
python·scrapy
数据小爬虫@1 天前
利用Python爬虫按图搜索1688商品(拍立淘):实战案例指南
爬虫·python·图搜索算法
奔跑吧邓邓子1 天前
【Python爬虫(3)】解锁Python爬虫技能树:深入理解模块与包
开发语言·爬虫·python·模块·
m0_748251721 天前
【论文投稿】Python 网络爬虫:探秘网页数据抓取的奇妙世界
爬虫·python·microsoft
大懒猫软件1 天前
使用 Python 爬虫和 FFmpeg 爬取 B 站高清视频
爬虫·python·ffmpeg
大数据学习爱好者2 天前
python旅游推荐系统+爬虫+可视化(协同过滤算法)
大数据·爬虫·python·深度学习·信息可视化
m0_748239832 天前
Python中的简单爬虫
爬虫·python·信息可视化
代码轨迹3 天前
使用DeepSeek+本地知识库,尝试从0到1搭建高度定制化工作流(爬虫模块篇)
人工智能·爬虫·python