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)
相关推荐
ycydynq2 小时前
自动化验证码实现
爬虫·自动化
c***42108 小时前
爬虫基础之爬取某基金网站+数据分析
爬虫·数据挖掘·数据分析
小白学大数据15 小时前
构建混合爬虫:何时使用Requests,何时切换至Selenium处理请求头?
爬虫·python·selenium·测试工具
4***721316 小时前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
爬虫·学习·计算机外设
t***316516 小时前
爬虫学习案例3
爬虫·python·学习
x***J3481 天前
Python多线程爬虫
开发语言·爬虫·python
m***D2861 天前
Python网络爬虫实战案例
开发语言·爬虫·python
青青子衿_212 天前
TikTok爬取——视频、元数据、一级评论
爬虫·python·selenium
interception2 天前
爬虫js逆向,jsdom补环境,抖音,a_bogus
javascript·爬虫·python
q***2512 天前
Python中的简单爬虫
爬虫·python·信息可视化