草庐IT

mongodb - 需要在mgo中使用分页

coder 2023-06-29 原文

我使用 Go 作为后端,MongoDB 作为数据库,使用 beego 框架来开发这个应用程序。我想在我的前端做一些分页。

我的结构看起来像这样:

type Employee struct {
        Name               string
        EmpId              string
        Password           string
        PhoneNumber        int32
        EmailAddress       string
        Position           string
        AccessLevel        string
        Gender             string
        MaritalStatus      string
        Nationality        string
        Department         string
        ICNumber           string
        JoinDate           time.Time
        ConfirmationDate   time.Time
        EndDate            time.Time
        AnnualLeave        []*AnnualLeaveInfo
        MedicalLeave       []*MedicalLeaveInfo
        NopayLeave         []*NopayLeaveInfo
        ChildcareLeave     []*ChildcareLeaveInfo
    }

type AnnualLeaveInfo struct {
        Id           int
        Days         float64
        Type         string
        From         time.Time
        To           time.Time
        AppliedDate  time.Time
        Status       string
        Certificate  []*CertificateInfo
    }

其他请假信息同年假信息。我想显示按申请日期和状态排序的所有员工文件的所有叶子。现在我正在检索所有休假详细信息,然后附加到数组中,然后我使用游标值(我在上一个响应中传递给前端的数组的最后检索索引值)并从数组中查找值.我知道这不是一个好函数,因为对于每个请求,它都需要检索所有休假详细信息,而仅检索前端请求的 20 个休假详细信息。

我添加到数组后的结果是这样的

  "0": {
    "LeaveEmpId": "rajeshk",
    "Name": "rahul",
    "LeaveId": 8,
    "LeaveType": "annualleave",
    "LeaveTotal": 2,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T10:29:33.713+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "1": {
    "LeaveEmpId": "rajeshk",
    "LeaveName": "Rajesh",
    "LeaveId": 7,
    "LeaveType": "medicalleave",
    "LeaveTotal": 3,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T10:27:06.12+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "2": {
    "LeaveEmpId": "kumar",
    "LeaveName": "madia",
    "LeaveId": 6,
    "LeaveType": "nopayleave",
    "LeaveTotal": 4,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T10:11:58.283+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "3": {
    "LeaveEmpId": "master",
    "LeaveName": "kumar",
    "LeaveId": 5,
    "LeaveType": "nopayleave",
    "LeaveTotal": 5,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T10:02:17.565+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "4": {
    "LeaveEmpId": "rajeshk",
    "LeaveName": "Rajesh",
    "LeaveId": 4,
    "LeaveType": "medicalleave",
    "LeaveTotal": 6,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T09:52:20.185+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "5": {
    "LeaveEmpId": "rajeshk",
    "LeaveName": "Rajesh",
    "LeaveId": 3,
    "LeaveType": "annualleave",
    "LeaveTotal": 7,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T09:49:18.702+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "6": {
    "LeaveEmpId": "india",
    "LeaveName": "rahul",
    "LeaveId": 2,
    "LeaveType": "nopayleave",
    "LeaveTotal": 8,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T09:30:14.99+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
  },
  "7": {
    "LeaveEmpId": "rajeshk",
    "LeaveName": "Rajesh",
    "LeaveId": 1,
    "LeaveType": "medicalleave",
    "LeaveTotal": 9,
    "LeaveDays": 1,
    "LeaveFrom": "2016-12-12T08:00:00+08:00",
    "LeaveTo": "2016-12-12T08:00:00+08:00",
    "LeaveAppliedDate": "2016-11-21T09:28:02.785+08:00",
    "LeaveStatus": "Processing",
    "CertificateName": [
      "1.pdf",
      "2.pdf"
    ]
 }

在数据库中,我的 empid 只是我使用的索引,它是唯一的,其他值不是唯一的。休假 ID 仅在休假数组中是唯一的。有人可以帮助我如何有效地做到这一点。感谢任何帮助。谢谢。

添加信息:

我的数据库结构如下所示...这只是一名员工的信息。像这样,我有很多员工文件。我需要的是获取所有这些员工文件的总休假详细信息,限制为 20 以按申请日期和状态排序分页。谢谢

{
    "_id" : ObjectId("58320cec720fed31a3243683"),
    "name" : "Rajesh",
    "empid" : "rajeshk",
    "password" : "c1e1a43a3d65ff4d669f2831b9908acb9e2f755c48280e99f0d7a3e92592fa29",
    "phonenumber" : 0,
    "emailaddress" : "example@example.com.sg",
    "position" : "string",
    "accesslevel" : "string",
    "gender" : "string",
    "maritalstatus" : "string",
    "nationality" : "india",
    "department" : "it",
    "icnumber" : "string",
    "childcitizenship" : "string",
    "joindate" : ISODate("2015-11-21T00:00:00.000Z"),
    "confirmationdate" : Date(-62135596800000),
    "enddate" : Date(-62135596800000),
    "totalchild" : 0,
    "annualleave" : [ 
        {

            "id" : 0,
            "days" : 0.0,
            "type" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "medicalleave" : [ 
        {

            "id" : 0,
            "days" : 0.0,
            "type" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "nopayleave" : [ 
        {
            "total" : 10.0,
            "id" : 0,
            "days" : 0.0,
            "type" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }, 
        {
            "total" : 9.0,
            "id" : 1,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T01:28:02.785Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 8.0,
            "id" : 2,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T01:30:14.990Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 7.0,
            "id" : 3,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T01:49:18.702Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 6.0,
            "id" : 4,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T01:52:20.185Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 5.0,
            "id" : 5,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T02:02:17.565Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 4.0,
            "id" : 6,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T02:11:58.283Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 3.0,
            "id" : 7,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T02:27:06.120Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }, 
        {
            "total" : 2.0,
            "id" : 8,
            "days" : 1.0,
            "mdays" : 0.0,
            "type" : "nopayleave",
            "daytype" : "FullDay",
            "from" : ISODate("2016-12-12T00:00:00.000Z"),
            "to" : ISODate("2016-12-12T00:00:00.000Z"),
            "applieddate" : ISODate("2016-11-21T02:29:33.713Z"),
            "status" : "Processing",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "",
            "certificate" : [ 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }, 
                {
                    "filename" : "Rajesh",
                    "filetype" : ".zip",
                    "filesize" : 1234
                }
            ]
        }
    ],
    "childcareleave" : [ 
        {
            "total" : 10.0,
            "id" : 0,
            "days" : 0.0,
            "type" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "hospitalleave" : [ 
        {
            "total" : 10.0,
            "id" : 0,
            "days" : 0.0,
            "mdays" : 0.0,
            "type" : "",
            "daytype" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificatename" : "string",
            "certificate" : []
        }
    ],
    "maternityleave" : [ 
        {
            "total" : 10.0,
            "id" : 0,
            "days" : 0.0,
            "mdays" : 0.0,
            "type" : "",
            "daytype" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "paternityleave" : [ 
        {
            "total" : 0.0,
            "id" : 0,
            "days" : 0.0,
            "mdays" : 0.0,
            "type" : "",
            "daytype" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "compassionateleave" : [ 
        {
            "total" : 0.0,
            "id" : 0,
            "days" : 0.0,
            "type" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "marriageleave" : [ 
        {
            "total" : 0.0,
            "id" : 0,
            "days" : 0.0,
            "type" : "",
            "from" : Date(-62135596800000),
            "to" : Date(-62135596800000),
            "applieddate" : Date(-62135596800000),
            "status" : "",
            "approveddate" : Date(-62135596800000),
            "certificate" : []
        }
    ],
    "otherleave" : []
}

最佳答案

事实上,您无法真正实现更高效的分页,因为您要列出和分页的所有文档都在一个文档中,分为多个 slice/数组。

为了实现高效简单的分页,我会重构您的模型。首先,我会将所有类型的 XXLeave 文档存储为同一类型 Leave,并向其添加一个属性,告诉您它是哪种休假(例如 年度医疗 等)。接下来,我不会将此列表存储在 Employee 本身中,而是存储在一个单独的 MongoDB 集合中,并且它可以有一个 EmployeeID 字段,告诉哪个员工 离开文档属于(所有者)。

有了这个模型,您可以轻松地列出员工的特定类型的 Leave 文档,查询如下:

c := session.DB("").C("leaves")
err := c.Find(bson.M{"empid": eid, "type": LeaveAnnual}).All(&result)

要列出员工的所有Leave 文档,只需不要使用"type" 过滤器:

err := c.Find(bson.M{"empid": eid}).All(&result)

现在开始分页。如果你有这个模型,分页就变得小菜一碟:

q = c.Find(bson.M{"empid": eid}).Sort("applieddate", "status")
// Use Skip() and Limit() to denote the page you want to send, e.g.
q = Skip((page-1) * 20).Limit(20)
err := q.All(&result)

如果你想在所有Leave 文档上发送和分页而不考虑Employee(作者),那么也忽略EmpId过滤器:

err := c.Find(nil).Sort("applieddate", "status").
    Skip((page-1) * 20).Limit(20).All(&result)

请注意,使用 Skip()Limit() 非常适合“少量”文档。但是对于大量文档,您应该使用基于指定起始索引条目的分页。有关更多详细信息和现成的库,请参阅此问题:

Efficient paging in MongoDB using mgo

关于mongodb - 需要在mgo中使用分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40796666/

有关mongodb - 需要在mgo中使用分页的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  5. ruby - 在 Ruby 中使用匿名模块 - 2

    假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于

  6. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  7. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  8. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  9. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  10. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

随机推荐