基于Everything实现的文件快速检索系统

NetWorkRequests 见 https://blog.csdn.net/CXY00000/article/details/132782514

# !/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
@author  : [email protected]
@des     :

"""
from lxml import etree
from sdk.utils.util_network import NetWorkRequests

ONE_SIZE = 32


class EverythingSearch(NetWorkRequests):
    def __init__(self):
        super(EverythingSearch, self).__init__()

    def anlise_result(self, html):
        """

        :param html:
        :return:
        """
        result = []
        tree = etree.HTML(html)
        result_search_nums = int(
            tree.xpath('//p[@class="numresults"]//text()')[0].split(" ")[0])
        if result_search_nums > 0:
            lis = tree.xpath('//tr//text()')
            if lis[4] == "修改日期":
                lis2 = lis[5:]
                temp = []
                for index, val in enumerate(lis2):
                    if index > 0 and index % 4 == 0:
                        result.append(temp)
                        temp = [val]
                    else:
                        temp.append(val)
            else:
                result = []

        return result

    def anlise_pages(self, html):
        """

        :param html:
        :return:
        """
        tree = etree.HTML(html)
        all_nums = int(tree.xpath('//tr//text()')
                       [0].split(" ")[-2].replace(",", ""))
        all_size = all_nums // ONE_SIZE if all_nums % ONE_SIZE == 0 else all_nums // ONE_SIZE + 1
        return all_nums, all_size

    def search(self, query, offset):
        """

        :param query:
        :param offset:
        :return:
        """
        headers = {
            "Authorization": "Basic YWRtaW46YWRtaW4=",
        }
        url = "http://localhost"
        params = {
            "search": "{}".format(query),
            "offset": "{}".format(offset)
        }
        res = self._requests(
            url=url,
            params=params,
            headers=headers,
            method="GET")
        if res["status"] == 0:
            html = res["msg"].text
            print("当前页数:{}".format(offset + 1))
            if offset == 0:
                all_nums, all_size = self.anlise_pages(html)
                # print(all_nums,all_size)
                if all_nums > 32:
                    for offset in range(1, all_size):
                        self.search(query, offset)
                else:
                    self.get_result(html)
            else:
                self.get_result(html)

    def get_result(self, html):
        anlise_result = self.anlise_result(html)
        if anlise_result:
            for args in anlise_result:
                name, path, size, date = args
                print(name, path, size, date)


if __name__ == '__main__':
    es = EverythingSearch()
    es.search("简历", 0)

  1. 首先要安装everything软件
  2. 开启everything http服务
  3. 网页登录 抓取到Authorization
  4. 使用上方脚本即可实现 快速搜索文件位置
    基于Everything实现的文件快速检索系统_第1张图片
    基于Everything实现的文件快速检索系统_第2张图片

    基于Everything实现的文件快速检索系统_第3张图片
    基于Everything实现的文件快速检索系统_第4张图片
    基于Everything实现的文件快速检索系统_第5张图片

你可能感兴趣的:(无用良品,python,开发语言)