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)
相关推荐
深蓝电商API6 小时前
常见反爬策略全解析
爬虫·反爬策略
honestman_14 小时前
Twitter/X 舆情监控与竞品分析实战指南
爬虫·twitter
CDN36015 小时前
IP 黑白名单防护实操:出海网站拦截恶意爬虫、扫描 IP,CDN 流量管控落地指南
网络·爬虫·tcp/ip
Data_Journal18 小时前
Playwright vs Selenium:哪个是最佳无头浏览器
开发语言·python·scrapy·microsoft·编辑器
跨境旺仔小拳头1 天前
如何使用Crawl4AI进行网页爬虫?从0搭建教程与代理配置指南
网络·人工智能·爬虫·chatgpt·aigc
傻啦嘿哟1 天前
某东商品爬虫实战:爬取商品价格+评论+销量,做竞品分析工具
爬虫
楷哥爱开发1 天前
IPFoxy爬虫代理配置指南:从0搭建Crawl4AI网页爬虫教程
大数据·运维·人工智能·爬虫
Data_Journal1 天前
如何使用 Python 抓取 Google Flights:分步指南
大数据·开发语言·数据库·python·scrapy
名字还没想好☜2 天前
Python asyncio.Queue 实战:用生产者-消费者给爬虫/任务流限速又解耦
开发语言·爬虫·python·并发·asyncio
2601_966949652 天前
Python 量化数据质量校验:如何确保股票历史日线数据不存在缺失交易日?
开发语言·人工智能·爬虫·python·量化策略·量化·quantdash