Page data protection method, device, equipment and medium
Through obfuscation and encryption of website page data, the problem that crawler programs can easily obtain website data is solved, and effective protection of website content is achieved.
Patent Information
- Application Number
- CN202411288665.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-09-14
AI Technical Summary
Crawlers are prone to obtain website page data by parsing HTML structure and URL patterns, resulting in abuse of website content and server performance.
By obtaining the first target element and page design of the target data, obfuscation processing is performed to generate obfuscation data, and finally the obfuscation data is integrated to generate page data that is difficult to crawl by the crawler program.
Through encryption and dynamic rendering, the resolution difficulty of crawler programs is increased, preventing target data from being leaked, and effectively protecting website content.
Smart Images

Figure CN118797582B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a page data protection method, device, equipment and medium. Background Art
[0002] The structure and content of traditional static pages are relatively fixed, and crawlers can easily obtain data by parsing HTML structure and URL patterns.
[0003] Anti-crawler technology plays an important role in protecting website content, ensuring server performance, maintaining user privacy and preventing malicious behavior. Summary of the invention
[0004] The present invention provides a page data protection method to solve the problem that a crawler program can easily obtain data by parsing HTML structure and URL mode.
[0005] In a first aspect, the present invention provides a page data protection method, the method comprising:
[0006] Obtaining the first target element of the target data and the page design;
[0007] Obfuscating the first target element according to the element type of the first target element to obtain first obfuscated data;
[0008] Obfuscating the page design to obtain second obfuscated data;
[0009] Page data is generated according to the first obfuscated data and the second obfuscated data.
[0010] In a second aspect, the present invention provides a page data protection device, comprising:
[0011] An acquisition unit, used for acquiring a first target element of target data and a page design;
[0012] A first obfuscation unit, configured to perform obfuscation processing on the first target element according to an element type of the first target element to obtain first obfuscated data;
[0013] A second obfuscation unit, configured to perform obfuscation processing on the page design to obtain second obfuscated data;
[0014] A generating unit is configured to render a page according to the first obfuscated data and the second obfuscated data.
[0015] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0016] Memory, used to store computer programs;
[0017] The processor is used to implement the steps of the page data protection method described in any embodiment of the first aspect when executing the program stored in the memory.
[0018] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the page data protection method as described in any embodiment of the first aspect are implemented.
[0019] The above technical solution provided by the embodiment of the present invention has the following advantages compared with the prior art:
[0020] The first obfuscated data encrypts the content of each question to prevent the leakage and abuse of sensitive information. The second obfuscated data increases the parsing difficulty of the crawler program, making it difficult to crawl the page data obtained by integrating the first obfuscated data and the second obfuscated data through fixed patterns and rules. Even if the page content is successfully downloaded, it is difficult to restore the first obfuscated data to obtain the target data, thereby achieving the effect of preventing the leakage of the target data. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 A schematic diagram of a flow chart of a page data protection method provided by an embodiment of the present invention;
[0024] Figure 2 An exemplary diagram of a first target element provided by an embodiment of the present invention;
[0025] Figure 3 An example diagram of second processed data provided by an embodiment of the present invention;
[0026] Figure 4 Another example diagram of a first target element provided by an embodiment of the present invention;
[0027] Figure 5 An example diagram of a third processing data provided by an embodiment of the present invention;
[0028] Figure 6A schematic diagram of the structure of a page data protection device provided by an embodiment of the present invention;
[0029] Figure 7 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] Example
[0032] Figure 1 The present invention provides a method for protecting page data. Figure 1 , the page data protection method includes the following steps S101-S104.
[0033] S101, obtaining a first target element of target data and a page design.
[0034] In a specific implementation, the elements of a page are the components that make up the page. Taking HTML elements as an example, HTML includes: <base> ,, <link> , <meta> , <style>、<title>、<body>等元素,具体为可参考现有资料确定;页面设计包括布局以及样式,继续以HTML元素举例,HTML中的<style>元素包含页面的布局以及样式,布局用于限定页面中的每个元素的位置,样式用于限定页面中的每个元素的大小、颜色、形状。
[0035] 在该实施例中,目标数据为网页试题数据,网页试题数据的<body>元素中包括多个题干,每个题干设有对应的序号、题目、附图以及选项,通过获取并拆解<body>元素,可以得到该网页试题数据的每个题干作为第一目标元素,用于后续步骤处理,可理解地,在其它一些实施例中,第一目标元素也可以选取每个题干中的序号、题目、附图以及选项任意一种或多种组合,本领域技术人员可灵活调整第一目标元素的元素组成,网页试题数据的页面设计限定了每个题干自上而下排列分布,10道题为一页且设有多个分页,每个题干的内容均为第一段落为序列号-题目,第二段落为附图,第三段落为选项的方式排列,每个题干的四周设有边框以及阴影。
[0036] S102,根据所述第一目标元素的元素类型将所述第一目标元素进行混淆处理,得到第一混淆数据。
[0037] 具体实施中,以HTML元素举例,HTML元素的元素类型包括块级元素、内联元素、内嵌元素、表单元素、空元素等,用于区分嵌入内容,例如:内嵌元素用于在网页中嵌入图像、音频、视频等。
[0038] 在该实施例中,以步骤S101获取的题干为例,分析题干中包含的元素类型,将序号、题目、附图以及选项分别进行混淆处理,得到混淆后的序号、题目、附图以及选项作为新的题干,将新的题干作为第一混淆数据,根据不同的元素类型作出不同的混淆处理,实现第一目标元素中的题干被下载也难以被还原和利用。
[0039] 在一实施例中,所述元素类型包括文本类型,以上步骤S102包括步骤:根据字符串替换算法以及噪音插入算法处理所述第一目标元素,得到第一处理数据,所述第一混淆数据包含所述第一处理数据。
[0040] 具体实施中,字符串替换算法用于将该元素中的文本进行字符替换,例如将某些关键字符替换为类似但不同的字符,或对文本进行编码加密,只有特定解码规则才能还原。噪音插入算法用于在文本中插入随机字符或无意义的噪音数据,干扰爬虫程序的解析。
[0041] 在该实施例中,第一目标元素包括题干的题目,第一目标元素的内容示例:"《朝花夕拾》中的《琐记》忆叙鲁迅为了寻找‘另一类的人们’而到南京求学的经过。作品批评了洋务派办学的‘乌烟瘴气’。作者记述了最初接触进化论的兴奋心情和不顾老辈反对,如饥如渴地阅读《天演论》的情景,表现出探求真理的强烈欲望。”,通过字符串替换算法以及噪音插入算法处理,得到的第一处理数据:"《朝花夕拾》中《琐记》忆叙迅为了寻找‘一类的人们’而京学的经过。品批评洋务办学的‘乌烟瘴气’。者记述了最初接化论的兴奋和顾老辈反对,如饥如渴地阅读《天》的,表出求真理的强烈欲望。”,通过字符替换、编码加密等方式,插入无意义的噪音数据,使文本内容丢失题意,干扰爬虫的解析。
[0042] 在一实施例中,所述元素类型包括图片类型,以上步骤S102包括步骤:根据像素扭曲算法处理所述第一目标元素,得到第二处理数据,所述第一混淆数据包含所述第二处理数据。
[0043] 具体实施中,像素扭曲算法包括像素进行扭曲或添加水印,使爬虫程序即便下载了图片,也难以还原出原始内容。
[0044] 在该实施例中,参见图2-3,图2为本发明实施例提供的一种第一目标元素的示例图,图3为本发明实施例提供的一种第二处理数据的示例图,通过像素扭曲、添加水印以及分割重组等技术,使得下载的图片数据难以恢复到原始状态。
[0045] 在一实施例中,所述元素类型还包括代码类型,以上步骤S102包括步骤:根据预设的加密算法处理所述第一目标元素,得到第三处理数据,所述第一混淆数据包含所述第三处理数据。
[0046] 具体实施中,以JavaScript代码为例,通过加密算法对JavaScript代码进行混淆和加密,使代码难以阅读和分析,增加爬虫解析难度,还可通过动态加载和执行脚本,改变第一目标元素的行为和内容。
[0047] 在该实施例中,参见图4-5,图4为本发明实施例提供的另一种第一目标元素的示例图,图5为本发明实施例提供的一种第三处理数据的示例图,将每个题干的组成重新排布,题干包括题目以及选项,通过加密算法动态渲染改变第一目标元素中题目与选项的排布,打乱爬虫程序的预定抓取策略。
[0048] S103,将所述页面设计进行混淆处理,得到第二混淆数据。
[0049] 具体实施中,页面设计包括布局以及样式,在HTML元素中,通过定义<style>元素中属性,可改变布局以及样式,在该实施例中,页面设计用于改变题干的排布方式,通过动态渲染技术改变题干的布局以及样式得到新的页面设计,例如将自上而下排列的方式改变为多排瀑布状的方式,将新的页面设计所定义的属性作为第二混淆数据。
[0050] 通过动态渲染技术使页面结构不断变化,大幅增加了爬虫程序的解析难度,每次用户访问时,页面的布局、样式和脚本都可能不同,这不仅打乱了爬虫程序的预定抓取策略,还迫使其每次都要重新适应变化的页面结构。这种动态变化使爬虫难以通过固定模式和规则进行有效抓取,从而显著降低了其成功率,保护网站内容免受未经授权的抓取。
[0051] 在一实施例中,以上步骤S103包括步骤:获取所述页面设计的样式数据,根据预设样式库以及所述样式数据动态生成新的样式数据,所述第二混淆数据包含所述新的样式数据。
[0052] 在该实施例中,样式包括字体大小、边框线条、背景颜色等,通过CSS样式库动态加载和应用样式,每次看到的页面样式有所不同,实现爬虫程序难以通过固定模式识别和抓取页面数据,从而有效保护网站内容。
[0053] 在一实施例中,以上步骤S103包括步骤:获取所述页面设计的布局数据,根据预设模板库以及所述布局数据动态生成新的布局数据,所述第二混淆数据包含所述新的布局数据。
[0054] 具体实施中,使用随机算法或预设模板动态生成页面布局,使每次访问时页面结构发生变化,例如:所有题干自上而下排列、所有题干以卡片形式并列排布等,实现爬虫程序难以通过固定模式识别和抓取页面数据,从而有效保护网站内容。
[0055] S104,根据所述第一混淆数据以及所述第二混淆数据生成页面数据。
[0056] 具体实施中,将第一混淆数据与第二混淆数据整合,得到页面数据,在该实施例中,页面数据与目标数据相比,已经将每个题干的内容加密,提高了数据隐私保护,还将所有题干的布局以及样式进行动态渲染,打乱爬虫程序的预定抓取策略。
[0057] 在一实施例中,提出了一种页面数据保护方法,包括上述任一项实施例所述的步骤,还包括以下步骤:
[0058] 解密所述第一混淆数据,得到第二目标元素;
[0059] 根据所述第二目标元素以及所述第二混淆数据渲染页面。
[0060] 具体实施中,解密第一混淆数据,包括步骤S102的逆过程,由此得到的第二目标元素的内容与第一目标元素的内容相同,在其它一些实施例中,也可以部分解密第一混淆数据,实现第二目标元素的内容与第一目标元素的内容部分相同,根据第二目标元素以及第二混淆数据渲染页面,该页面用于展示,实现展示的第二目标元素以及第二混淆数据渲染页面,爬虫程序抓包的是第一混淆数据以及所述第二混淆数据生成的页面数据,在不明显干扰用户操作的前提下,有效防止爬虫行为。相比于频繁使用验证码等传统反爬虫手段,第一混淆数据与第二混淆数据动态渲染,不明显干扰用户操作,提供用户流畅的访问体验。
[0061] 本发明实施例可实现以下优点:
[0062] 第一混淆数据将每个题干的内容加密,防止敏感信息泄露和被滥用,通过第二混淆数据增加了爬虫程序的解析难度,实现将第一混淆数据以及第二混淆数据整合得到的页面数据难以通过固定模式和规则进行抓取,即使成功下载了页面内容,也难以将第一混淆数据还原得到目标数据,进而取得防止目标数据泄露的效果。
[0063] 参见图6本发明实施例还提供了一种页面数据保护装置400,该页面数据保护装置包括获取单元401、第一混淆单元402、第二混淆单元403以及生成单元404。
[0064] 获取单元401,用于获取目标数据的第一目标元素以及页面设计。
[0065] 第一混淆单元402,用于根据所述第一目标元素的元素类型将所述第一目标元素进行混淆处理,得到第一混淆数据。
[0066] 在一实施例中,所述元素类型包括文本类型,所述根据所述第一目标元素的元素类型将所述第一目标元素进行混淆处理,得到第一混淆数据,包括:
[0067] 根据字符串替换算法以及噪音插入算法处理所述第一目标元素,得到第一处理数据,所述第一混淆数据包含所述第一处理数据。
[0068] 在一实施例中,所述元素类型还包括图片类型,所述根据所述第一目标元素的元素类型将所述第一目标元素进行混淆处理,得到第一混淆数据,包括:
[0069] 根据像素扭曲算法处理所述第一目标元素,得到第二处理数据,所述第一混淆数据包含所述第二处理数据。
[0070] 在一实施例中,所述元素类型还包括代码类型,所述根据所述第一目标元素的元素类型将所述第一目标元素进行混淆处理,得到第一混淆数据,包括:
[0071] 根据预设的加密算法处理所述第一目标元素,得到第三处理数据,所述第一混淆数据包含所述第三处理数据。
[0072] 第二混淆单元403,用于将所述页面设计进行混淆处理,得到第二混淆数据。
[0073] 在一实施例中,将所述页面设计进行混淆处理,得到第二混淆数据,包括:
[0074] 获取所述页面设计的样式数据,根据预设样式库以及所述样式数据动态生成新的样式数据,所述第二混淆数据包含所述新的样式数据。
[0075] 在一实施例中,将所述页面设计进行混淆处理,得到第二混淆数据,包括:
[0076] 获取所述页面设计的布局数据,根据预设模板库以及所述布局数据动态生成新的布局数据,所述第二混淆数据包含所述新的布局数据。
[0077] 生成单元404,用于根据所述第一混淆数据以及所述第二混淆数据生成页面数据。
[0078] 在一实施例中,本发明实施例还提供了一种页面数据保护装置,该页面数据保护装置包括如上述任一实施例所述的获取单元、第一混淆单元、第二混淆单元以及生成单元,还包括解密单元以及渲染单元。
[0079] 解密单元,用于解密所述第一混淆数据,得到第二目标元素。
[0080] 渲染单元,根据所述第二目标元素以及所述第二混淆数据渲染页面。
[0081] 如图7所示,图7是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备500可以是终端,也可以是服务器,其中,终端可以是智能手机、平板电脑、笔记本电脑、台式电脑、个人数字助理和穿戴式设备等具有通信功能的电子设备。服务器可以是独立的服务器,也可以是多个服务器组成的服务器集群。
[0082] 该计算机设备500包括通过系统总线501连接的处理器502、存储器和网络接口505,其中,存储器可以包括非易失性存储介质503和内存储器504。
[0083] 该非易失性存储介质503可存储操作系统5031和计算机程序5032。该计算机程序5032被执行时,可使得处理器502执行一种页面数据保护方法。
[0084] 该处理器502用于提供计算和控制能力,以支撑整个计算机设备500的运行。
[0085] 该内存储器504为非易失性存储介质503中的计算机程序5032的运行提供环境,该计算机程序5032被处理器502执行时,可使得处理器502执行一种页面数据保护方法。
[0086] 该网络接口505用于与其它设备进行网络通信。本领域技术人员可以理解,上述结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备500的限定,具体的计算机设备500可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
[0087] 应当理解,在本申请实施例中,处理器502可以是中央处理单元 (CentralProcessing Unit,CPU),该处理器502还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路 (Application Specific IntegratedCircuit,ASIC)、现成可编程门阵列 (Field-Programmable Gate Array,FPGA) 或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
[0088] 本领域普通技术人员可以理解的是实现上述实施例的方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成。该计算机程序可存储于一存储介质中,该存储介质为计算机可读存储介质。该计算机程序被该计算机系统中的至少一个处理器执行,以实现上述方法的实施例的流程步骤。
[0089] 因此,本发明还提供一种存储介质。该存储介质可以为计算机可读存储介质。该存储介质存储有计算机程序。
[0090] 所述存储介质为实体的、非瞬时性的存储介质,例如可以是U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、磁碟或者光盘等各种可以存储程序代码的实体存储介质。所述计算机可读存储介质可以是非易失性,也可以是易失性。
[0091] 本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。
[0092] 在本发明所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的。例如,各个单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。
[0093] 本发明实施例方法中的步骤可以根据实际需要进行顺序调整、合并和删减。本发明实施例装置中的单元可以根据实际需要进行合并、划分和删减。另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。
[0094] 该集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,终端,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。
[0095] 在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详细描述的部分,可以参见其他实施例的相关描述。
[0096] 显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,尚且本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。
[0097] 以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。< / style>
Claims
1. A page data protection method, characterized in that: The method comprises: Obtaining the first target element of the target data and the page design; Obfuscating the first target element according to the element type of the first target element to obtain first obfuscated data; Obfuscating the page design to obtain second obfuscated data; Generate page data according to the first obfuscated data and the second obfuscated data; The obfuscating the page design to obtain the second obfuscated data includes: obtaining layout data of the page design, dynamically generating new layout data according to a preset template library and the layout data, wherein the second obfuscated data includes the new layout data, and the layout data includes the number of page structure arrangements and the arrangement form of the page structure; Decrypting the first obfuscated data to obtain a second target element; Render a page according to the second target element and the second obfuscated data.
2. The method according to claim 1, characterized in that The element type includes a text type, and the obfuscating the first target element according to the element type of the first target element to obtain first obfuscated data includes: The first target element is processed according to a string replacement algorithm and a noise insertion algorithm to obtain first processed data, and the first obfuscated data includes the first processed data.
3. The method according to claim 1, characterized in that The element type further includes a picture type, and the obfuscating the first target element according to the element type of the first target element to obtain first obfuscated data includes: The first target element is processed according to a pixel distortion algorithm to obtain second processed data, and the first obfuscated data includes the second processed data.
4. The method according to claim 1, characterized in that: The element type further includes a code type, and the obfuscating the first target element according to the element type of the first target element to obtain first obfuscated data includes: The first target element is processed according to a preset encryption algorithm to obtain third processed data, and the first obfuscated data includes the third processed data.
5. The method according to claim 1, characterized in that: Obfuscating the page design to obtain second obfuscated data includes: The style data of the page design is obtained, and new style data is dynamically generated according to a preset style library and the style data, wherein the second obfuscated data includes the new style data.
6. A page data protection device, characterized in that: include: An acquisition unit, used for acquiring a first target element of target data and a page design; A first obfuscation unit, configured to perform obfuscation processing on the first target element according to an element type of the first target element to obtain first obfuscated data; A second obfuscation unit is configured to perform an obfuscation process on the page design to obtain second obfuscated data; wherein, the performing an obfuscation process on the page design to obtain the second obfuscated data comprises: obtaining layout data of the page design, dynamically generating new layout data according to a preset template library and the layout data, wherein the second obfuscated data comprises the new layout data, and the layout data comprises the number of arrangements of the page structure and the arrangement form of the page structure; A generating unit, configured to render a page according to the first obfuscated data and the second obfuscated data; A decryption unit, used for decrypting the first obfuscated data to obtain a second target element; A rendering unit is used to render a page according to the second target element and the second obfuscated data.
7. A computer device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the steps of the method described in any one of claims 1 to 5 when executing a program stored in a memory.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Crawler prevention method and device, computer readable storage medium and electronic equipment
CN113791965A
Anti-crawler method and device and medium
CN116346377A