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)
相关推荐
cch89183 分钟前
PHP爬虫框架大比拼
开发语言·爬虫·php
ZC跨境爬虫41 分钟前
Playwright模拟鼠标滚轮实战:从原理到百度图片_豆瓣电影爬取
爬虫·python·计算机外设
ZC跨境爬虫15 小时前
极验滑动验证码自动化实战:背景提取、缺口定位与Playwright滑动模拟
前端·爬虫·python·自动化
ZC跨境爬虫20 小时前
极验滑动验证码自动化实战(ddddocr免费方案):本地缺口识别与Playwright滑动模拟
前端·爬虫·python·自动化
后藤十八里21 小时前
极验4消消乐验证码逆向笔记
笔记·爬虫·python
后藤十八里1 天前
极验4滑动拼图验证码逆向笔记
笔记·爬虫·python
ZC跨境爬虫2 天前
免费验证码识别:用ddddocr实现Playwright自动化登录
爬虫·python·自动化
ZC跨境爬虫2 天前
Playwright进阶操作:鼠标拖拽与各类点击实战(含自定义拖拽实例)
前端·爬虫·python·ui
Pocker_Spades_A2 天前
Python快速入门专业版(五十六)——爬虫会话管理:Cookie与Session原理及实战(保持登录状态)
开发语言·爬虫·python
进击的雷神3 天前
攻克多级导航循环与class属性ID提取:基于双层循环架构的精准爬虫设计
爬虫·架构