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)
相关推荐
hugh_oo3 小时前
100 天学会爬虫 · Day 11:如何合理控制爬虫请求频率?让访问行为更像真人
开发语言·爬虫·python
Wpa.wk5 小时前
自动化测试 - 文件上传 和 弹窗处理
开发语言·javascript·自动化测试·经验分享·爬虫·python·selenium
逆向新手6 小时前
js逆向-某省特种设备aes加密研究
javascript·爬虫·python·逆向·js
sugar椰子皮8 小时前
【node阅读-1】node架构了解
爬虫
Caco.D8 小时前
Aneiang.Pa 高阶用法:动态爬虫 SDK 详解与实战
爬虫·aneiang.pa
有味道的男人8 小时前
淘宝图片搜索(拍立淘)+ 店铺全商品爬虫 深度实战指南(Python)
开发语言·爬虫·python
一招定胜负1 天前
网络爬虫(第三部)
前端·javascript·爬虫
interception1 天前
爬虫逆向:瑞数5(华能电子)
爬虫
光算科技1 天前
商品颜色/尺码选项太多|谷歌爬虫不收录怎么办
java·javascript·爬虫
是Yu欸1 天前
扫描网站结构的SEO元数据抓取方案
爬虫·seo·亮数据·brightdata