Method, device and equipment for analyzing style, medium and program product

By using the main thread to determine the style task set for parallel processing when rendering a web page, and using multi-threaded parallel parsing, the problem of low parsing styles in the existing technology is solved, and faster web page rendering speed is achieved.

CN119903258APending Publication Date: 2025-04-29BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510094014.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

In the prior art, when rendering web pages, parsing styles are low, resulting in slower rendering of web pages.

Method used

By using the main thread to determine the task set of multiple nodes at multiple layers in the target element tree, including tasks based on selectors and inline styles, and using multiple threads to parse these tasks in parallel, the parallel processing of style tasks is achieved.

Benefits of technology

Improve the efficiency of analyzing the target element tree, reduce the overall parsing time, and improve the web rendering speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119903258A_ABST
    Figure CN119903258A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for analyzing a style, equipment, a storage medium and a computer program product. The method includes determining, using a main thread, a set of tasks for a plurality of nodes of a plurality of layers of a target element tree according to the target element tree and a web page style for a target page, the set of tasks including at least one of a selector-based style task and an inline style-based style task. The method also includes parsing a plurality of tasks in the task set in parallel using a plurality of threads. According to the method disclosed by the embodiment of the invention, the plurality of tasks aiming at the plurality of nodes of the plurality of layers in the target element tree are obtained through splitting by using the main thread, and then the plurality of tasks are executed in parallel by using the plurality of threads, so that the parallel processing of the style tasks can be simultaneously performed across the plurality of layers, and the efficiency of analyzing the target element tree is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates generally to the field of computers, and more particularly to a method, an apparatus, a device, a computer-readable storage medium, and a computer program product for parsing a pattern. Background Art

[0002] The development of web page rendering technology enables web pages to present information in a more intuitive and clear way. For example, HyperText Markup Language (HTML) can build the information structure and framework of web pages, and Cascading Style Sheets (CSS) can beautify and layout information, making it easier for people to read and understand.

[0003] With the development of computer technology and the Internet, CSS is used more and more widely. It separates the content of web pages from their presentation, allowing developers to more flexibly control the style of web pages, such as fonts, colors, backgrounds, layouts, etc. HTML is also constantly being updated, with more tags and attributes, allowing web pages to present more complex structures and content. Summary of the invention

[0004] According to example embodiments of the present disclosure, a method, apparatus, device, computer storage medium, and computer program product for parsing a pattern are provided.

[0005] In a first aspect of the present disclosure, a method for parsing styles is provided, the method comprising, according to a target element tree and a webpage style for a target page, using a main thread to determine a task set for multiple nodes of multiple layers of a target element tree, the task set comprising at least one of a selector-based style task and an inline-style-based style task. The method further comprises using multiple threads to parse multiple tasks in the task set in parallel.

[0006] In a second aspect of the present disclosure, a device for parsing styles is provided, the device comprising a splitting module configured to determine a task set for multiple nodes of multiple layers of a target element tree using a main thread according to a target element tree and a webpage style for a target page, the task set comprising at least one of a selector-based style task and an inline-style-based style task. The device further comprises an execution module configured to parse multiple tasks in the task set in parallel using multiple threads.

[0007] In a third aspect of the present disclosure, an electronic device is provided, comprising: at least one processing unit; and at least one memory, wherein the at least one memory is coupled to the at least one processing unit and stores instructions for execution by the at least one processing unit, which instructions, when executed by the at least one processing unit, enable the electronic device to execute the method described in the first aspect of the present disclosure.

[0008] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, which has machine-executable instructions stored thereon, and when the machine-executable instructions are executed by a device, the device performs the method described in the first aspect of the present disclosure.

[0009] In a fifth aspect of the present disclosure, a computer program product is provided, comprising computer executable instructions, wherein the computer executable instructions implement the method described according to the first aspect of the present disclosure when executed by a processor.

[0010] The invention summary is provided to introduce a series of concepts in a simplified form, which will be further described in the specific embodiments below. The invention summary is not intended to identify the key features or essential features of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easy to understand through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 A schematic diagram illustrating an example environment in which embodiments of the present disclosure can be implemented;

[0012] Figure 2 A flowchart of a method for parsing a pattern according to an embodiment of the present disclosure is shown;

[0013] Figure 3 A schematic diagram of determining a task set according to an embodiment of the present disclosure is shown;

[0014] Figure 4 A schematic diagram showing a method of determining a parallel task result according to an embodiment of the present disclosure is shown;

[0015] Figure 5 A schematic diagram showing a method for parsing a pattern according to an embodiment of the present disclosure is shown;

[0016] Figure 6 A schematic diagram showing execution of a second task set according to an embodiment of the present disclosure is shown;

[0017] Figure 7 A schematic block diagram showing an example apparatus according to some embodiments of the present disclosure is shown;

[0018] Figure 8A block diagram of an example device that may be used to implement embodiments of the present disclosure is shown.

[0019] Throughout the drawings, the same or similar reference numbers denote the same or similar elements. DETAILED DESCRIPTION

[0020] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only for illustrative purposes and are not used to limit the scope of these messages or information. It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the type, scope of use, and usage scenarios of the personal information involved in the present disclosure should be informed to the user in an appropriate manner in accordance with relevant laws and regulations and the user's authorization should be obtained.

[0021] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can independently choose whether to provide personal information to software or hardware such as an electronic device, application, server or storage medium that performs the operation of the technical solution of the present disclosure based on the prompt message. As an optional but non-limiting implementation method, in response to receiving an active request from a user, the method of sending a prompt message to the user can be, for example, a pop-up window, and the prompt message can be presented in text in the pop-up window. In addition, the pop-up window can also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0022] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0023] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0024] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects, unless explicitly stated. Other explicit and implicit definitions may also be included below.

[0025] When rendering the layout and typesetting of a web page, the structure of the web page elements (i.e., the element tree) is usually determined first, and then the styles of each element in the element tree are rendered. When rendering the styles of each element in the element tree, the styles of each element can be parsed first according to the style code for the element tree, and the style instructions that the rendering engine can understand are generated, and then the rendering engine is used to implement the styles of each element, thereby rendering the entire web page. In the related art, the styles of the elements in the nodes are usually parsed in node order according to the tree structure of the element tree, that is, the elements of the root node of the first layer in the element tree are first parsed, and then the elements of each node in the second layer are parsed one by one according to the parsing result of the element, and so on, until the elements of all the nodes of the element tree are parsed. In other technologies, the elements of all the nodes of a single layer can be parsed in parallel, for example, the elements of all the nodes of the second layer are parsed in parallel according to the parsing result of the element of the root node, and the elements of all the nodes of the third layer are parsed in parallel according to the parsing result, and so on, until the elements of all the nodes of the element tree are parsed. However, the parsing efficiency is still low, resulting in a slow speed in rendering web pages.

[0026] In this regard, the present disclosure proposes a method for parsing styles. The method uses a main thread to determine multiple tasks for multiple nodes at multiple layers in a target element tree, the multiple tasks are at least one of style tasks based on selectors and inline styles, and then uses multiple threads to execute the multiple tasks in parallel, which can simultaneously perform parallel processing of style tasks across multiple layers (even at the element tree level), thereby further improving the efficiency of parsing the target element tree.

[0027] The embodiments of the present disclosure will be described in detail below in conjunction with the accompanying drawings. Figure 1 A schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented is shown. The example environment 100 includes a computing device 110 and a computing device 120. In some embodiments, the computing device 120 communicates with the computing device 110 via a network 130. The network 130 may include a wired network, a wireless network, or a combination thereof, for providing communication between the computing device 120 and the computing device 110. In some embodiments, the computing device 120 may be connected to the computing device 110 via a data line, and the present disclosure does not limit the connection method between the computing device 110 and the computing device 120.

[0028] In this embodiment, when a user enters a uniform resource locator in the browser address bar on the computing device 120 or requests to display a target page by clicking a link, the computing device 120 will construct an HTTP (Hypertext Transfer Protocol) request based on the uniform resource locator to request to display the target page. The computing device 120 can send this request to the network 130, resolve the uniform resource locator into an IP address through the domain name system server, and then find the computing device 110 containing the page file of the target page according to the IP address. After receiving the request, the computing device 110 will search for the corresponding page file according to the resource path of the request, and return the page file to the computing device 120 as a response. This process may involve multiple network nodes and protocols, such as passing through routers, firewalls and other devices, and may use protocols such as TCP / IP to ensure reliable data transmission.

[0029] After the computing device 120 obtains the page file of the target page (e.g., a file containing HTML code segments and CSS code segments), it needs to render the page file to display it on the display for the user to view. In an embodiment, after the computing device 120 obtains the page file, it can generate a target element tree based on the page file. The elements of each node in the target element tree constitute the page information of the target page. For example, the elements of the nodes of the target element tree can be a block (DIV) of the target page, a title (such as " <h1> Page title< / h1> ”), paragraphs, etc. Figure 1 In the example, the target element tree includes three nodes, namely block nodes 142, 144, and 146. Each block node may also include a subtree for the block, and the nodes of these subtrees may include elements such as titles, lists, paragraphs, etc. In this embodiment, it is assumed that each subtree includes two layers for the convenience of description.

[0030] In this embodiment, the computing device 120 can use the main thread to determine a task set 154 for multiple nodes 142-146 of multiple layers of the target element tree according to the target element tree and the web page style for the target page, and the task set includes at least one of a selector-based style task and an inline style-based style task. For example, the element of the root node of each subtree hits the selector 148, the element of the lower left node of each subtree hits the selector 150, and the element of the lower right node of each subtree hits the selector 152. For example, the selector 148 can be a paragraph selector, and the elements of the root node of each subtree are just paragraph elements with p tags, then the elements of these three root nodes all hit the selector 148. In some embodiments, the structures of the subtrees can be different from each other. For example, the element of the root node of subtree 142 can be a paragraph element, and the element of the root node of subtree 144 can be a title element. In an embodiment, the web page style associated with the element of a certain node can be an inline style, that is, the style of the element is recorded separately and uniquely in the web page style. Then a parsing task can be determined based on the inline style and the element.

[0031] The computing device 120 may traverse the target element tree formed by the nodes 142-146 to determine a task set 154 including multiple tasks. The task set 154 includes a task to parse the root node of each subtree according to the style specified by the selector 148, a task to parse the lower left node of each subtree according to the style specified by the selector 150, and a task to parse the lower right node of each subtree according to the style specified by the selector 152.

[0032] In this embodiment, an executor 156 is provided in the computing device 120, and the executor 156 can use multiple threads to parse multiple tasks in the task set 154 in parallel. In order to speed up this process, the executor 156 can use multi-threading technology to allow multiple tasks to be performed simultaneously. For example, the executor 156 can call some or all of the idle threads in the thread pool to execute tasks. This means that the computing device 120 can parse and apply styles to different elements or levels at the same time, instead of processing each task one by one in sequence. This parallel processing method improves efficiency because there is no need to wait for a task to be completed before starting the next task. On the contrary, multiple tasks can be processed at the same time, thereby reducing the overall parsing time. After the parsing is completed, the calculated styles for each element in the target element tree can be obtained, and the renderer in the computing device 120 can render the target page according to these calculated styles and display it in the target page for the user to view.

[0033] like Figure 1As shown, in environment 100, network 130 can be used to transmit data between computing device 110 and computing device 120. Network 130 has a theoretical bandwidth, which refers to the maximum transmission speed supported by network 130, which indicates the maximum amount of data that can be transmitted by network 130 under ideal conditions, usually measured in bits per second (bps). For example, if the theoretical bandwidth of network 130 is 100Mbps, it means that it can transmit one hundred megabits of data per second under ideal conditions. However, in reality, due to other factors that may exist in the network (e.g., signal interference, bandwidth sharing, transmission delay, etc.), the actual transmission speed of 100Mbps may not be achieved.

[0034] As understood by those skilled in the art, an instance of the computing device 110 may be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The server may be directly or indirectly connected via wired or wireless communications, which is not limited in this application.

[0035] The computing device 120 may be any type of mobile computing device, including a mobile computer (e.g., a personal digital assistant (PDA), a laptop computer, a notebook computer, a tablet computer, a netbook, etc.), a mobile phone (e.g., a cellular phone, a smart phone, etc.), a wearable computing device (e.g., a smart watch, a head-mounted device, including smart glasses, etc.), or other types of mobile devices. In some embodiments, the computing device 120 may also be a stationary computing device, such as a desktop computer, a game console, a smart TV, etc.

[0036] It should be understood that the architecture and functions in the example environment 100 are described for exemplary purposes only and do not imply any limitation on the scope of the present disclosure. Embodiments of the present disclosure may also be applied to other environments with different structures and / or functions.

[0037] The process according to the embodiment of the present disclosure will be described in detail below in conjunction with other drawings. For ease of understanding, the specific data mentioned in the following description are exemplary and are not intended to limit the scope of protection of the present disclosure. It is understood that the embodiments described below may also include additional actions not shown and / or the actions shown may be omitted, and the scope of the present disclosure is not limited in this respect.

[0038] Figure 2A flowchart of a method 200 for parsing styles according to certain embodiments of the present disclosure is shown. In this embodiment, the method can be performed by a computing device 120. In box 202, based on the target element tree and the web page style for the target page, a task set for multiple nodes of multiple layers of the target element tree is determined using the main thread, and the task set includes at least one of a selector-based style task and an inline style-based style task. The target element tree can be, for example, a Document Object Model (DOM) tree. The styles of corresponding elements in the target element tree are defined in the web page style. A selector is a pattern or rule for locating (or selecting) elements in a target element tree (or HTML document). For example, a selector includes a tag selector, which selects elements based on the name of an HTML tag. For example, the p selector selects all elements in the target element tree. element. If the rule "p{color:blue;}" is defined in the web page style, then all The text color of the element will be set to blue. Selectors can also include other types of selectors, such as class selectors, ID selectors, child selectors, parent selectors, adjacent sibling selectors, ancestor selectors, and so on.

[0039] Inline styles are a way to define CSS styles directly inside the tags of an HTML document. By writing CSS style rules in the style attribute of an HTML tag, you can set the style for that specific tag instead of in a separate CSS file or in the head of the HTML document. <style>标签中定义样式。在该实施例中,在遍历到目标元素树的某个节点的元素时,其关联的网页样式如果是内联样式,则可以根据该内联样式和该节点的元素确定为任务集合中的一个任务。

[0040] 在框204,使用多个线程并行解析任务集合中的多个任务。因为该多个任务要是仅基于选择器的,要不是基于内联样式,这意味着这些任务的样式是明确的、不会存在变动的可能性。例如如果图1中的选择器148定义了段落的颜色是蓝色,则根据该选择器和目标元素树确定的三个任务都可以被执行为将相应三个节点的元素设置为蓝色,而不会出现其他颜色的可能。因此这些任务都可以被并行执行。由于网页样式的层叠性的存在,可能出现多个任务是针对同一元素的情况,这种情况下可以将同一元素的多个样式根据优先级进行聚合,从而得到该元素最终的样式。也就是说,不管任务集合中的多个任务是否存在重复定义或层叠性的情况,都可以先并行执行各个任务,再聚合任务结果得到目标元素树的多个层的多个节点的元素的样式。

[0041] 根据本公开的实施例的方法,该方法使用主线程确定针对目标元素树中的多个层的多个节点的多个任务,该多个任务是基于选择器和内联样式的样式任务中的至少一项,进而使用多个线程并行执行该多个任务,能够跨越多个层(甚至在元素树级别)同时进行样式任务的并行处理,从而提高解析目标元素树的效率。

[0042] 在确定任务集合时,可以通过遍历目标元素树中的每个节点,并访问该节点的元素相关联的网页样式来确定任务集合中每一个任务。图3示出了根据本公开的实施例确定任务集合的示意图。在302处,使用主线程遍历目标元素树中的各个节点。在遍历过程中,针对每个节点的元素执行后续操作。在304处,针对当前遍历到的节点,使用主线程从网页样式中确定关联的网页样式,该关联的网页样式定义了该当前节点的元素的样式。在306处,使用主线程检测相关联的网页样式是否包括选择器。在实施例中,使用主线程检测相关联的网页样式是否包括自身选择器、父节点的选择器、或祖先节点的选择器中的一个选择器。

[0043] 在308处,如果节点相关联的网页样式包括选择器,使用主线程将针对节点和相关联的网页样式的解析任务确定为任务集合中的任务。即该任务指示将该元素的样式确定为相关联的网页样式所定义的样式。在实施例中,相关联的网页样式包括自身选择器、父节点的选择器、或祖先节点的选择器中的至少一个选择器,使用主线程将针对节点和相关联的网页样式的解析任务确定为任务集合中的任务。

[0044] 如果不包括选择器,在310处,使用主线程检测相关联的网页样式是否包括内联样式。在312处,如果节点相关联的网页样式包括内联样式,使用主线程将针对节点和相关联的网页样式的解析任务确定为任务集合中的任务。

[0045] 针对框204,在执行过程中,可以将对样式的定义转换为渲染器158可以理解的指令。在实施例中,基于预设匹配规则,使用多个线程将任务集合映射为多个计算样式。在样式解析过程中,预设匹配规则是选择器与目标元素树的节点之间的匹配。主线程可以遍历网页样式中的每个选择器,并将其与目标元素树中的节点进行匹配。例如,对于一个简单的标签选择器如h1,主线程会在目标元素树中查找所有<h1>标签节点,并将h1选择器对应的样式规则应用到这些节点的元素上。对于复杂的选择器,如后代选择器(例如"body h1”),主线程会在目标元素树中先找到<body>节点,然后在其后代节点中寻找<h1>节点。这种匹配是基于目标元素树的层次结构进行的。在匹配到元素的样式后,需要将其转换为渲染器158可理解的数据,即生成元素的计算样式。计算样式是一组在显示元素时实际使用的属性值。

[0046] 在实施例中,根据多个计算样式,确定并行任务结果。如果该多个计算样式都是针对不同元素的,没有层叠的情况出现,那么可以直接将这些计算样式作为并行任务结果。如果存在层叠的情况,则可以在聚合之后确定并行任务结果。只要任务集合中的某个任务是基于选择器或内联样式,则该任务可以被执行,以得到计算样式。虽然该计算样式可能最终不被采用,例如任务集合中的另一个任务针对相同的元素也定义了某种样式(例如颜色为红色),且具有更高的优先级,在可以在生成计算样式后,根据优先级规则对这两个计算样式进行聚合,确定该元素最终的计算样式。

[0047] 图4示出了根据本公开的实施例的确定并行任务结果的示意图。在402处,通过节点的元素与网页样式的匹配,可以确定任务集合404。针对存在层叠的情况,在实施例中,根据目标元素树,确定与多个计算样式对应的多个元素。其中元素1的样式匹配有三种,元素2的样式匹配有两种,元素3的样式匹配有一种。

[0048] 在414处,对元素的样式进行聚合,以得到并行任务结果416。在实施例中,针对多个元素中的每个元素,如果多个计算样式中的一部分计算样式都是针对元素的计算样式,通过根据预设优先级规则聚合一部分计算样式,来确定元素的样式。针对元素1,通过匹配样式408、410、412具有不同的优先级,将具有最高优先级的匹配样式确定为元素1的匹配样式418,以实现聚合。例如,确定的元素1的匹配样式418可以是与元素1相关联的内联样式。类似的,元素2的样式可以从两种匹配样式中确定优先级较高的一个样式作为元素2的样式。针对各个元素都进行聚合,从而得到多个元素的样式。在实施例中,将多个元素的样式确定为并行任务结果416。

[0049] 图5示出了根据本公开的实施例的用于解析样式的方法的示意图。在该实施例中,目标元素树502以及相应网页样式被输入到任务生成器504中,任务生成器504根据网页样式来遍历目标元素树502,以得到任务集合。任务生成器504将任务集合发送给任务调度器510。任务调度器510可以调用线程池512。线程池512中的空闲线程的数量可以实时确定。在实施例中,线程池512有预定数目的线程(例如10个),任务集合的任务数目是第一数目(例如1000个),并且该第一数目大于预定数目。

[0050] 为了能够快速地并行解析任务集合中的多个任务,任务调度器510可以调用线程池512中的多个线程来来并行解析该任务集合中的多个任务。在实施例中,将任务集合划分为第二数目的任务子集合,其中第二数目小于或者等于预定数目。例如可以将1000个任务分成10组,每组100个任务,任务调度器510为每组任务分配一个线程来执行。在实施例中,使用预定数目的线程并行执行第二数目的任务子集合。通过并行执行第二数目的任务子集合,可以充分利用空闲线程并提高目标页面的解析效率。如图5所示,可以初步解析得到元素div0的三种样式匹配,元素div1的两种样式匹配,元素div2的一种样式匹配,等等。进一步地,该多个线程可以聚合存在层叠的样式,以得到并行任务结果。在实施例中,如果主线程执行结束,使用主线程执行第二数目的任务子集合的至少一个任务子集合,这样可以进一步提高并行执行任务集合的效率。

[0051] 然后网页样式中除了选择器和内联样式,还可能包括其他样式,例如层叠样式表变量和继承元素。节点的元素的关联的网页样式中如果定义了变量或者继承元素则需要根据元素的上下文来推导该元素的属性值,这意味着无法通过并行了完成样式任务。例如节点1中的元素的颜色等于变量a。如果要确定该元素的颜色到底是多少,则需要遍历目标元素中,逐节点计算变量a的变量值的变化,直到遍历到节点1时确定变量a此时的变量值,例如白色,则可以确定该元素的颜色基于变量a而设置为白色。

[0052] 在实施例中,任务生成器504在遍历目标元素树502时,根据目标元素树和网页样式,使用主线程确定第二任务集合,其中第二任务集合包括基于变量的样式任务和基于继承元素的样式任务中的至少一项。任务生成器504例如可以将其放到后置同步器514中处理。在实施例中,后置同步处理器514使用主线程,串行执行第二任务集合。如上所描述的,后置同步处理器514同样需要遍历目标元素树502来完成对第二任务集合的执行,从而得到针对目标元素树502的各个元素的计算样式516。

[0053] 在该实施例中,解析目标元素树时既有并行任务又有串行任务,对此本方法使用任务生成器来拆分得到代表各个并行任务的任务集合,和代表串行任务的第二任何集合,实现一次性对目标元素树的所有解析任务的全部拆分。然后将两种任务分别执行,这样目标元素树中所有能够并行的样式任务可以都通过并行执行来完成解析,这可以极大地提高解析效率,同时串行任务可以在第二次遍历过程中逐步完成解析,从而确保实现对包含多种样式的目标元素树的完整解析。

[0054] 在一些情况下,由于样式层叠性的存在,在后置同步处理器514解析第二任务集合后,仍然需要将存储在层叠样式的元素进行处理,以计算元素的最终样式。如果第二任务集合中的一个任务是基于变量的任务,在实施例中,使用主线程通过遍历目标元素树来确定变量在第一节点的变量值。在实施例中,从并行任务结果中获取第一节点的第一元素的计算样式。在实施例中,基于预设优先级规则,根据变量值来更新第一元素的计算样式。

[0055] 图6示出了根据本公开的实施例的执行第二任务集合的示意图。在634处,任务生成器可以确定第一元素与变量a匹配。在636处,在串行执行第二任务集合中的一个任务的过程中,遍历目标元素树后确定第一元素的颜色被设置为变量a,变量在此节点处指示白色。在638处,将第一元素的计算样式确定为基于变量a而为白色。在并行执行任务集合的过程中,根据相关联的第一选择器,第一元素的颜色被设置为蓝色,这被记录在并行任务结果632中。在640处,根据预设优先级规则,如果第一选择器的优先级高于变量a的优先级,则第一元素的颜色为蓝色,否则为白色。照此确定第一元素的计算样式,以实现样式再聚合。在642处,结束该任务的执行。第二任务集合的其他任务如果也涉及层叠性,也是这样处理。

[0056] 类似地,如果第二任务集合中的一个任务是基于继承元素的任务,在实施例中,如果目标元素树中的第二节点的第二元素继承第三元素,使用主线程通过遍历目标元素树来确定第三元素的属性值。在实施例中,从并行任务结果中获取第二元素的计算样式。在实施例中,基于预设优先级规则,根据属性值来更新第二元素的计算样式。在该实施例中,基于并行任务结果和变量值或集成元素,根据预设优先级规则通过再次聚合来确定元素的计算样式,可以针对目标元素树实现准确的解析,同时由于并行处理的执行,可以改进解析效率。

[0057] 图7示出了根据本公开的一些实施例的示例装置700的示意框图。装置700可以通过软件、硬件或者两者结合的方式实现。如图7所示,装置700包括拆分模块710、执行模块720。

[0058] 在一些实施例中,拆分模块710可以配置为根据针对目标页面的目标元素树和网页样式,使用主线程确定针对目标元素树的多个层的多个节点的任务集合,任务集合包括基于选择器的样式任务和基于内联样式的样式任务中的至少一项。执行模块720可以配置为使用多个线程并行解析任务集合中的多个任务。

[0059] 在一些实施例中,拆分模块710包括遍历模块,配置为基于网页样式遍历目标元素树并针对每一个节点执行下述操作,响应于节点相关联的网页样式包括选择器,使用主线程将针对节点和相关联的网页样式的解析任务确定为任务集合中的任务;以及响应于节点相关联的网页样式包括内联样式,使用主线程将针对节点和相关联的网页样式的解析任务确定为任务集合中的任务。

[0060] 在一些实施例中,遍历模块包括检测模块,配置为使用主线程检测相关联的网页样式是否包括自身选择器、父节点的选择器、或祖先节点的选择器中的一个选择器。遍历模块还包括第一确定模块,配置为响应于相关联的网页样式包括自身选择器、父节点的选择器、或祖先节点的选择器中的至少一个选择器,使用主线程将针对节点和相关联的网页样式的解析任务确定为任务集合中的任务。

[0061] 在一些实施例中,执行模块720包括映射模块,配置为基于预设匹配规则,使用多个线程将任务集合映射为多个计算样式。执行模块720还包括第二确定模块,配置为根据多个计算样式,确定并行任务结果。

[0062] 在一些实施例中,第二确定模块包括第三确定模块,配置为根据目标元素树,确定与多个计算样式对应的多个元素。第二确定模块还包括第四确定模块,配置为针对多个元素中的每个元素,响应于多个计算样式中的一部分计算样式都是针对元素的计算样式,通过根据预设优先级规则聚合一部分计算样式,来确定元素的样式。第二确定模块还包括第五确定模块,配置为将多个元素的样式确定为并行任务结果。

[0063] 在一些实施例中,任务集合的任务数目是第一数目,多个线程的数目是预定数目,第一数目大于预定数目,并且执行模块720包括划分模块,配置为将任务集合划分为第二数目的任务子集合,其中第二数目小于或者等于预定数目。执行模块720包括第二执行模块,配置为使用预定数目的线程并行执行第二数目的任务子集合。

[0064] 在一些实施例中,装置700还包括第三执行模块,配置为响应于主线程执行结束,使用主线程执行第二数目的任务子集合的至少一个任务子集合。

[0065] 在一些实施例中,装置700还包括第六确定模块,配置为根据目标元素树和网页样式,使用主线程确定第二任务集合,其中第二任务集合包括基于变量的样式任务和基于继承元素的样式任务中的至少一项。装置700还包括串行执行模块,配置为使用主线程,串行执行第二任务集合。

[0066] 在一些实施例中,任务集合中的多个任务被解析后得到并行任务结果,并且串行执行模块包括变量模块,配置为响应于第二任务集合中的一个任务是基于变量的任务,使用主线程执行下述操作,通过遍历目标元素树来确定变量在第一节点的变量值;从并行任务结果中获取第一节点的第一元素的计算样式;以及基于预设优先级规则,根据变量值来更新第一元素的计算样式。

[0067] 在一些实施例中,串行执行模块包括继承模块,配置为响应于第二任务集合中的一个任务是基于继承元素的任务,使用主线程执行下述操作,响应于目标元素树中的第二节点的第二元素继承第三元素,通过遍历目标元素树来确定第三元素的属性值;从并行任务结果中获取第二元素的计算样式;以及基于预设优先级规则,根据属性值来更新第二元素的计算样式。

[0068] 本公开的实施例中对模块或单元的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时也可以有另外的划分方式,另外,在公开的实施例中的各功能单元可以集成在一个单元中,也可以是单独物理存在,也可以两个或两个以上单元集成为一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。

[0069] 图8示出了可以用来实施本公开的实施例的示例设备800的框图。应当理解,图8所示出的设备800仅仅是示例的,而不应当构成对本文所描述的实现方式的功能和范围的任何限制。例如,可以使用设备800可以对应与本文中结合图1所描述的计算设备110,并且可以用来执行上文描述的图1至图6的过程。

[0070] 如图8所示,设备800是通用计算设备的形式。计算设备800的组件可以包括但不限于一个或多个处理器或处理单元810、存储器820、存储设备830、一个或多个通信单元840、一个或多个输入设备850以及一个或多个输出设备860。处理单元810可以是实际或虚拟处理器并且能够根据存储器820中存储的程序来执行各种处理。在多处理器系统中,多个处理单元并行执行计算机可执行指令,以提高计算设备800的并行处理能力。

[0071] 计算设备800通常包括多个计算机存储介质。这样的介质可以是计算设备800可访问的任何可以获得的介质,包括但不限于易失性和非易失性介质、可拆卸和不可拆卸介质。存储器820可以是易失性存储器(例如寄存器、高速缓存、随机访问存储器(Random AccessMemory,RAM))、非易失性存储器(例如,只读存储器(Read Only Memory,ROM)、电可擦除可编程只读存储器(Electrically Erasable Programmable Read Only Memory,EEPROM)、闪存)或它们的某种组合。存储设备830可以是可拆卸或不可拆卸的介质,并且可以包括机器可读介质,诸如闪存驱动、磁盘或者任何其他介质,其可以能够用于存储信息和 / 或数据(例如用于训练的训练数据)并且可以在计算设备800内被访问。

[0072] 计算设备800可以进一步包括另外的可拆卸 / 不可拆卸、易失性 / 非易失性存储介质。尽管未在图8中示出,可以提供用于从可拆卸、非易失性磁盘(例如"软盘”)进行读取或写入的磁盘驱动和用于从可拆卸、非易失性光盘进行读取或写入的光盘驱动。在这些情况中,每个驱动可以由一个或多个数据介质接口被连接至总线(未示出)。存储器820可以包括计算机程序产品825,其具有一个或多个程序模块,这些程序模块被配置为执行本公开的各种实现方式的各种方法或动作。

[0073] 通信单元840实现通过通信介质与其他计算设备进行通信。附加地,计算设备800的组件的功能可以以单个计算集群或多个计算机器来实现,这些计算机器能够通过通信连接进行通信。因此,计算设备800可以使用与一个或多个其他服务器、网络个人计算机(Personal Computer,PC)或者另一个网络节点的逻辑连接来在联网环境中进行操作。

[0074] 输入设备850可以是一个或多个输入设备,例如鼠标、键盘、追踪球等。输出设备860可以是一个或多个输出设备,例如显示器、扬声器、打印机等。计算设备800还可以根据需要通过通信单元840与一个或多个外部设备(未示出)进行通信,外部设备诸如存储设备、显示设备等,与一个或多个使得用户与计算设备800交互的设备进行通信,或者与使得计算设备800与一个或多个其他计算设备通信的任何设备(例如,网卡、调制解调器等)进行通信。这样的通信可以经由输入 / 输出(Input / Output,I / O)接口(未示出)来执行。

[0075] 根据本公开的示例实现方式,提供了一种计算机可读存储介质,其上存储有计算机可执行指令,其中计算机可执行指令被处理器执行以实现上文描述的方法。根据本公开的示例实现方式,还提供了一种计算机程序产品,计算机程序产品被有形地存储在非瞬态计算机可读介质上并且包括计算机可执行指令,而计算机可执行指令被处理器执行以实现上文描述的方法。根据本公开的示例实现方式,提供了一种计算机程序产品,其上存储有计算机程序,程序被处理器执行时实现上文描述的方法。

[0076] 这里参照根据本公开实现的方法、装置、设备和计算机程序产品的流程图和 / 或框图描述了本公开的各个方面。应当理解,流程图和 / 或框图的每个方框以及流程图和 / 或框图中各方框的组合,都可以由计算机可读程序指令实现。

[0077] 这些计算机可读程序指令可以提供给通用计算机、专用计算机或其他可编程数据处理装置的处理单元,从而生产出一种机器,使得这些指令在通过计算机或其他可编程数据处理装置的处理单元执行时,产生了实现流程图和 / 或框图中的一个或多个方框中规定的功能 / 动作的装置。也可以把这些计算机可读程序指令存储在计算机可读存储介质中,这些指令使得计算机、可编程数据处理装置和 / 或其他设备以特定方式工作,从而,存储有指令的计算机可读介质则包括一个制造品,其包括实现流程图和 / 或框图中的一个或多个方框中规定的功能 / 动作的各个方面的指令。

[0078] 可以把计算机可读程序指令加载到计算机、其他可编程数据处理装置、或其他设备上,使得在计算机、其他可编程数据处理装置或其他设备上执行一系列操作步骤,以产生计算机实现的过程,从而使得在计算机、其他可编程数据处理装置、或其他设备上执行的指令实现流程图和 / 或框图中的一个或多个方框中规定的功能 / 动作。

[0079] 附图中的流程图和框图显示了根据本公开的多个实现的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或指令的一部分,模块、程序段或指令的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和 / 或流程图中的每个方框、以及框图和 / 或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。

[0080] 以上已经描述了本公开的各实现,上述说明是示例的,并非穷尽性的,并且也不限于所公开的各实现。在不偏离所说明的各实现的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。本文中所用术语的选择,旨在最好地解释各实现的原理、实际应用或对市场中的技术的改进,或者使本技术领域的其他普通技术人员能理解本文公开的各个实现方式。< / style>

Claims

1. A method for parsing a style, comprising: According to the target element tree and the webpage style for the target page, using the main thread to determine a task set for multiple nodes of multiple layers of the target element tree, the task set including at least one of a selector-based style task and an inline-style-based style task; as well as Multiple threads are used to parse multiple tasks in the task set in parallel.

2. The method according to claim 1, wherein according to the target element tree and the webpage style for the target page, using the main thread to determine the task set for multiple nodes of multiple layers of the target element tree comprises: Traverse the target element tree based on the web page style and perform the following operations for each node: In response to the webpage style associated with the node including a selector, using the main thread to determine a parsing task for the node and the associated webpage style as a task in the task set; as well as In response to the webpage style associated with the node including an inline style, the main thread is used to determine a parsing task for the node and the associated webpage style as a task in the task set.

3. The method according to claim 2, wherein in response to the webpage style associated with the node including a selector, using the main thread to determine the parsing task for the node and the associated webpage style as a task in the task set comprises: Using the main thread to detect whether the associated webpage style includes a selector of its own selector, a selector of a parent node, or a selector of an ancestor node; as well as In response to the associated webpage style including at least one of the self selector, the parent node's selector, or the ancestor node's selector, the main thread is used to determine a parsing task for the node and the associated webpage style as a task in the task set.

4. The method according to claim 2, wherein using multiple threads to parse multiple tasks in the task set in parallel comprises: Based on a preset matching rule, mapping the task set into a plurality of computing styles using the plurality of threads; as well as According to the multiple computing patterns, parallel task results are determined.

5. The method according to claim 4, wherein determining the parallel task results according to the multiple computing patterns comprises: Determining, according to the target element tree, a plurality of elements corresponding to the plurality of calculation patterns; For each of the multiple elements, in response to a portion of the multiple calculation patterns being calculation patterns for the element, determining a pattern of the element by aggregating the portion of the calculation patterns according to a preset priority rule; as well as The patterns of the plurality of elements are determined as the parallel task results.

6. The method according to claim 1, wherein the number of tasks in the task set is a first number, the number of the plurality of threads is a predetermined number, the first number is greater than the predetermined number, and using the plurality of threads to parse the plurality of tasks in the task set in parallel comprises: Dividing the task set into a second number of task subsets, wherein the second number is less than or equal to the predetermined number; as well as The second number of task subsets are executed in parallel using the predetermined number of threads.

7. The method according to claim 6, further comprising: In response to the main thread finishing execution, at least one task subset of the second number of task subsets is executed using the main thread.

8. The method according to claim 1, further comprising: Determine a second task set using the main thread according to the target element tree and the webpage style, wherein the second task set includes at least one of a variable-based style task and an inherited element-based style task; as well as The second task set is executed serially using the main thread.

9. The method according to claim 8, wherein the plurality of tasks in the task set are parsed to obtain parallel task results, and the second task set is executed serially using the main thread, comprising: In response to a task in the second task set being the variable-based task, using the main thread to perform the following operations: Determine the variable value of the variable at the first node by traversing the target element tree; Obtaining a calculation pattern of a first element of the first node from the parallel task result; as well as Based on a preset priority rule, the calculation pattern of the first element is updated according to the variable value.

10. The method according to claim 8, wherein using the main thread to serially execute the second set of tasks comprises: In response to a task in the second task set being the inherited element-based task, using the main thread to perform the following operations: In response to the second element of the second node in the target element tree inheriting the third element, determining the attribute value of the third element by traversing the target element tree; Obtaining a calculation pattern of the second element from the parallel task result; as well as Based on a preset priority rule, the calculation pattern of the second element is updated according to the attribute value.

11. An apparatus for parsing a pattern, comprising: a splitting module configured to determine, based on a target element tree and a webpage style for a target page, a task set for multiple nodes of multiple layers of the target element tree using a main thread, wherein the task set includes at least one of a selector-based style task and an inline-style-based style task; as well as The execution module is configured to use multiple threads to parse multiple tasks in the task set in parallel.

12. An electronic device comprising: at least one processing unit; At least one memory, the at least one memory being coupled to the at least one processing unit and storing tasks for execution by the at least one processing unit, the tasks, when executed by the at least one processing unit, causing the electronic device to execute the method according to any one of claims 1 to 10.

13. A computer program product having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method according to any one of claims 1 to 10.