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)
相关推荐
TLuoQiu7 小时前
小电视视频内容获取GUI工具
爬虫·python
麦麦大数据16 小时前
F004 新闻可视化系统爬虫更新数据+ flask + mysql架构
爬虫·mysql·flask·可视化·新闻
python-行者17 小时前
akamai鼠标轨迹
爬虫·python·计算机外设·akamai
NEUMaple1 天前
python爬虫(四)----requests
开发语言·爬虫·python
电商API_180079052472 天前
大规模调用淘宝商品详情 API 的分布式请求调度实践
服务器·数据库·分布式·爬虫
小白学大数据2 天前
1688商品数据抓取:Python爬虫+动态页面解析
爬虫·python·okhttp
forestsea2 天前
Nginx蜘蛛请求智能分流:精准识别爬虫并转发SEO渲染服务
运维·爬虫·nginx
华科云商xiao徐2 天前
突破Python性能墙:关键模块C++化的爬虫优化指南
c++·爬虫·python
guidovans2 天前
基于大语言模型的爬虫数据清洗与结构化
人工智能·爬虫·语言模型·自然语言处理
憨憨の大鸭鸭2 天前
python爬虫学习(2)
爬虫·学习