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)
相关推荐
傻啦嘿哟4 小时前
长效住宅代理IP:反爬虫战场上的隐形盾牌
爬虫·网络协议·tcp/ip
华科云商xiao徐6 小时前
冷门但好用的Python库写个爬虫代码
爬虫
华科云商xiao徐6 小时前
Koa+Puppeteer爬虫教程页面设计
爬虫
Python×CATIA工业智造9 小时前
列表页与详情页的智能识别:多维度判定方法与工业级实现
爬虫·深度学习·pycharm
失败又激情的man20 小时前
python之requests库解析
开发语言·爬虫·python
爬虫程序猿20 小时前
利用爬虫按关键字搜索淘宝商品实战指南
android·爬虫
打酱油的;20 小时前
爬虫-数据解析
爬虫
打酱油的;20 小时前
爬虫-request处理get
爬虫·python·django
布语world1 天前
2025快手创作者中心发布视频python实现
爬虫·python
浏览器API调用工程师_Taylor1 天前
Look my eyes 都2025年了,你还不会将重复的事情自动化?
前端·javascript·爬虫