CN112099875A - Webpage loading method and device and electronic equipment - Google Patents

Webpage loading method and device and electronic equipment Download PDF

Info

Publication number
CN112099875A
CN112099875A CN202010994240.3A CN202010994240A CN112099875A CN 112099875 A CN112099875 A CN 112099875A CN 202010994240 A CN202010994240 A CN 202010994240A CN 112099875 A CN112099875 A CN 112099875A
Authority
CN
China
Prior art keywords
script
webpage data
data
node
page
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010994240.3A
Other languages
Chinese (zh)
Inventor
赵剑萍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Shenzhen Huantai Technology Co Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
Shenzhen Huantai Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Oppo Mobile Telecommunications Corp Ltd, Shenzhen Huantai Technology Co Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN202010994240.3A priority Critical patent/CN112099875A/en
Publication of CN112099875A publication Critical patent/CN112099875A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9027Trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • G06F9/45508Runtime interpretation or emulation, e g. emulator loops, bytecode interpretation
    • G06F9/45512Command shells
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/02Marketing; Price estimation or determination; Fundraising
    • G06Q30/0241Advertisements
    • G06Q30/0277Online advertisement

Abstract

The application discloses a webpage loading method and device and electronic equipment. The method comprises the following steps: receiving first webpage data issued by a server; under the condition that the first webpage data represent webpage data under a subframe page, injecting a first script into the first webpage data; removing a first node in a DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data; and rendering the page based on the second DOM tree.

Description

Webpage loading method and device and electronic equipment
Technical Field
The present application relates to the field of web page technologies, and in particular, to a web page loading method and apparatus, and an electronic device.
Background
In the related art, the frame technology can be used to display the web page data corresponding to different hypertext Markup Language (HTML) documents in different areas of the same page of the browser. In the related art, when a browser loads a webpage, advertisements in each area of the webpage cannot be removed.
Disclosure of Invention
In view of this, embodiments of the present application are expected to provide a method, an apparatus, and an electronic device for loading a web page, so as to solve the technical problem in the related art that advertisements in each area of the web page cannot be removed.
In order to achieve the purpose, the technical scheme of the application is realized as follows:
the embodiment of the application provides a webpage loading method, which comprises the following steps:
receiving first webpage data issued by a server;
under the condition that the first webpage data represent webpage data under a subframe page, injecting a first script into the first webpage data;
removing a first node in a DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data;
and rendering the page based on the second DOM tree.
In the above scheme, the method further includes:
when a first DOM tree corresponding to the first webpage data is generated, abandoning to create a DOM node corresponding to a first label in the first webpage data; wherein the content of the first and second substances,
the first label is the same as the set label; the content under the set label is characterized as an advertisement.
In the above scheme, the method further includes:
and after the page corresponding to the first webpage data is rendered, under the condition that the dynamically inserted first label is detected in the page, abandoning to create a DOM node corresponding to the dynamically inserted first label.
In the foregoing solution, the injecting the first script into the first webpage data includes:
searching a subframe tag corresponding to the first webpage data in a set white list;
under the condition that the subframe tag corresponding to the first webpage data is not found in the set white list, injecting a first script into the first webpage data; wherein the content of the first and second substances,
the set white list comprises at least one subframe tag.
In the foregoing solution, the injecting the first script into the first webpage data includes:
reading the first script from the inner core of the browser, and injecting the read first script into the first webpage data; wherein the content of the first and second substances,
and the first script is saved in the kernel of the browser when the browser is started and initialized.
In the above scheme, the method further includes:
when the browser is started, determining whether a pre-cached first script is invalid or not based on a timestamp of the pre-cached first script;
under the condition that the pre-cached first script is not invalid and the browser initialization is completed, saving the pre-cached first script to a kernel of the browser;
and under the condition that the pre-cached first script is invalid, downloading the first script from the server, and saving the downloaded first script in a kernel of the browser when the browser initialization is completed.
In the foregoing solution, the injecting the first script into the first webpage data further includes:
injecting a first script into the first web page data before a kernel of the browser is started.
Above-mentioned scheme still includes:
reporting the related information of the first label to the server; and the related information of the first label is used for the server to update the first script.
An embodiment of the present application provides a web page loading apparatus, including:
the receiving unit is used for receiving first webpage data issued by the server;
the injection unit is used for injecting a first script into the first webpage data under the condition that the first webpage data represent the webpage data under the subframe page;
the advertisement removing unit is used for removing a first node in a first DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data;
and the rendering unit is used for rendering the page based on the second DOM tree.
An embodiment of the present application further provides an electronic device, including: a processor and a memory for storing a computer program operable on the processor, wherein the processor is configured to implement any of the above-described web page loading methods when the computer program is executed by the processor.
The embodiment of the application also provides a storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method for loading the web page is implemented.
According to the embodiment of the application, the browser has the function of injecting the script into the webpage data corresponding to the subframe page, the electronic device can inject the first script into the first webpage data when receiving the first webpage data under the subframe page, and by executing the first script injected into the first webpage data, the DOM node containing the advertisement data in the first DOM tree corresponding to the first webpage data is removed to obtain the second DOM tree, so that the corresponding subframe page is rendered based on the second DOM tree. By injecting the first script into the first webpage data of the sub-frame page, the advertisement node in the DOM tree corresponding to the first webpage data under the sub-frame page can be accurately deleted, so that the sub-frame page without the advertisement is displayed, and the condition that the sub-frame page cannot be displayed due to incomplete deletion or error of the advertisement node in the DOM tree corresponding to the sub-frame page and the related data under the advertisement node can be avoided. Because the second DOM tree does not have DOM nodes containing advertisement data, the DOM nodes containing the advertisement data are removed before the page is rendered based on the second DOM tree, and advertisement flash does not occur in the process of rendering the page. Wherein the advertisement impression is caused by deleting a DOM node containing advertisement data in the process of rendering the page.
Drawings
Fig. 1 is a schematic flow chart illustrating an implementation process of a web page loading method according to an embodiment of the present application;
fig. 2 is a schematic flow chart illustrating an implementation process of a web page loading method according to another embodiment of the present application;
fig. 3 is a schematic flow chart illustrating an implementation of a web page loading method according to yet another embodiment of the present application;
fig. 4 is a schematic view illustrating an implementation flow of a web page loading method according to another embodiment of the present application;
FIG. 5 is a schematic flow chart illustrating an implementation of injecting a first script according to an embodiment of the present application;
fig. 6 is a schematic flow chart of an implementation of saving a first script according to an embodiment of the present application;
fig. 7 is a schematic view of an implementation flow of a web page loading method according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a web page loading apparatus according to an embodiment of the present application;
fig. 9 is a schematic diagram of a hardware component structure of an electronic device according to an embodiment of the present application.
Detailed Description
The frame technology in the webpage technology is mainly realized by a frame set and a frame, wherein the frame set is used for dividing a main frame page displayed by a browser into at least two areas; each area is a frame and is used for displaying page data corresponding to the sub-frame page.
In the related art, a web page loading method is provided for a web page implemented by using a frame technology, and a browser injects an advertisement removal script into web page data corresponding to a main frame page when loading the web page, executes the advertisement removal script when analyzing the web page data to remove advertisement data in the web page data corresponding to the main frame page, and renders the corresponding main frame page based on an analysis result of removing the advertisement data. Because the advertisement removal script cannot be injected into the webpage data corresponding to the sub-frame page, the advertisement removal script cannot be executed when the webpage data corresponding to the sub-frame page is analyzed, so that the advertisement in the sub-frame page cannot be removed.
Another web page loading method is also provided in the related art, in which an advertisement removal script injected into web page data corresponding to a main frame page is executed, an advertisement node in a Document Object Model (DOM) tree corresponding to page data of a subframe page is searched for, so that the searched advertisement node is deleted, and the corresponding subframe page is rendered based on the DOM tree from which the advertisement node is deleted. In addition, when the browser is configured with a cross-region security limit, the advertisements in the sub-frame page cannot be removed by using the cross-frame advertisement removing method.
In view of the foregoing technical problems, an embodiment of the present application provides a web page loading method, in which a browser adds a function of injecting a script into web page data corresponding to a subframe page, and injects a first script into first web page data of the subframe page, so as to remove an advertisement node in a DOM tree corresponding to the first web page data through the first script injected into the first web page data, and render a corresponding subframe page based on the DOM tree from which the advertisement node is removed. By injecting the first script into the first webpage data of the sub-frame page, the advertisement node in the DOM tree corresponding to the first webpage data under the sub-frame page can be accurately deleted, so that the sub-frame page without the advertisement is displayed, and the condition that the sub-frame page cannot be displayed due to incomplete deletion or error deletion of the advertisement node in the DOM tree corresponding to the sub-frame page can be avoided.
The technical solution of the present application is further described in detail with reference to the drawings and specific embodiments of the specification.
Fig. 1 shows a schematic implementation flow diagram of a web page loading method provided by an embodiment of the present application, in the embodiment of the present application, an execution main body of the method is an electronic device, a browser is installed in the electronic device, and the electronic device includes a mobile phone, a tablet computer, a desktop computer, and the like.
Referring to fig. 1, a method for loading a web page provided in an embodiment of the present application includes:
s101: and receiving first webpage data sent by a server.
The electronic device sends a first Uniform Resource Locator (URL) to the server when detecting that the browser in the electronic device is currently started. The first URL may be entered by a user in an input box of a browser.
The server searches first webpage data corresponding to the first URL from the database under the condition that the first URL sent by the electronic equipment is received, and issues the first webpage data corresponding to the first URL to the electronic equipment under the condition that the first webpage data corresponding to the first URL is found.
S102: and under the condition that the first webpage data represent the webpage data under the subframe page, injecting a first script into the first webpage data.
The method comprises the steps that under the condition that electronic equipment receives first webpage data sent by a server, whether the first webpage data represent webpage data under a subframe page or not is detected; when the first webpage data represent webpage data under the subframe page, the electronic equipment injects the first script into the first webpage data to obtain second webpage data. Here, the electronic device injects the first script into the first web page data by calling a first Application Programming Interface (API) of the browser.
In practical application, the electronic device may search for a subframe tag corresponding to the first webpage data, and the first webpage data represents webpage data under a subframe page under the condition that the corresponding subframe tag is found; and under the condition that the corresponding subframe tag is not found, the first webpage data represent the webpage data under the main frame page. Wherein the subframe tag comprises one of: frame, Iframe.
In practical application, when the first webpage data is webpage data loaded for the first time after the browser is started, the first webpage data represents webpage data below the main frame page.
S103: removing a first node in a first DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data.
Here, the first script characterizes a script for identifying advertisement data. For example, to identify URLs, pops, floats, tags, etc. that contain advertising data. The first script includes, but is not limited to, a JavaScript script. The first script is used for deleting DOM nodes containing advertisement data in the DOM tree.
The electronic equipment analyzes the first webpage data to obtain a first DOM tree corresponding to the first webpage data, and deletes a first node in the first DOM tree and related data under the first node by executing a first script injected into the first webpage data to obtain a second DOM tree.
S104: and rendering the page based on the second DOM tree.
The browser in the electronic device constructs a rendering tree based on the second DOM tree and a Cascading Style Sheet Object Model (CSSOM) tree, and renders a corresponding subframe page based on the constructed rendering tree. Wherein the content of the first and second substances,
CSSOM is built based on the browser's CSS style sheet in the process of generating the second DOM tree. And when the rendering tree is constructed, the browser traverses the DOM nodes in the second DOM tree, searches the style of the current DOM node in the CSSOM tree, and generates the rendering tree.
It should be noted that, when the first webpage data represents the webpage data under the main frame page, the electronic device calls the second API of the browser to inject the first script into the first webpage data, so as to remove the DOM node containing the advertisement data by executing the first script injected into the first webpage data, thereby rendering the corresponding main frame page. In practical applications, when the first script is injected into the web page data, the first API and the second API that are called may be the same or different.
In the solution provided in this embodiment of the application, the browser adds a function of injecting a script into the webpage data corresponding to the subframe page, and the electronic device may inject the first script into the first webpage data when receiving the first webpage data under the subframe page, and remove a DOM node containing advertisement data in the first DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data, so as to obtain a second DOM tree, thereby rendering the corresponding subframe page based on the second DOM tree. By injecting the first script into the first webpage data of the sub-frame page, the advertisement node in the DOM tree corresponding to the first webpage data can be accurately deleted, so that the sub-frame page without the advertisement is displayed, and the condition that the sub-frame page cannot be displayed due to incomplete deletion or error deletion of the advertisement node in the DOM tree corresponding to the factor frame page can be avoided.
Because the second DOM tree does not have DOM nodes containing advertisement data, the DOM nodes containing the advertisement data are removed before the page is rendered based on the second DOM tree, and advertisement flash does not occur in the process of rendering the page.
Referring to fig. 2, as another embodiment provided by the present application, on the basis of the embodiment corresponding to fig. 1, the method for loading a web page further includes:
s105: when a first DOM tree corresponding to the first webpage data is generated, abandoning to create a DOM node corresponding to a first label in the first webpage data; wherein, the first label is the same label as the set label; the content under the set label is characterized as an advertisement.
When the electronic device analyzes the first webpage data, detecting whether a first label obtained by current analysis is the same as a set label, and under the condition that the first label obtained by current analysis is the same as the set label, abandoning to create a DOM node corresponding to the first label; and under the condition that the first label obtained by current analysis is different from the set label, creating a DOM node corresponding to the first label, and generating a first DOM tree based on the created DOM node.
In practical application, the electronic device searches a setting tag which is the same as the currently analyzed tag in the setting list, and abandons creation of the DOM node corresponding to the first tag in the first webpage data under the condition that the setting tag which is the same as the currently analyzed tag is found. Wherein, at least one setting label is stored in the setting list.
After the electronic device finishes executing S105, in the process of executing S103, the tag corresponding to the first node may be identified as a setting tag, and when the setting list does not include the tag corresponding to the first node, the tag corresponding to the first node may be written into the setting list, so as to update the setting list.
In fig. 2, the first web page data may be web page data below a subframe page, or may be web page data below a main frame page.
In the scheme provided by this embodiment, when the first tag obtained by current parsing is the same as the set tag, the DOM node corresponding to the first tag is not created, so that the number of DOM nodes corresponding to the first webpage data can be reduced, the time consumed by subsequently searching for the first node is reduced, and the speed of displaying the webpage is increased.
Because the second DOM tree is obtained after the DOM nodes containing the advertisement data in the first DOM tree are removed by executing the first script, the DOM nodes corresponding to the first tag do not exist in the first DOM tree, the DOM nodes containing the advertisement data do not exist in the second DOM tree, all the advertisement data in the first page data are deleted before the page is rendered based on the second DOM tree, and the advertisement flash can not occur in the process of rendering the page.
Referring to fig. 3, as another embodiment provided by the present application, the method for loading a web page further includes:
s106: and after the page corresponding to the first webpage data is rendered, under the condition that the dynamically inserted first label is detected in the page, abandoning to create a DOM node corresponding to the dynamically inserted first label.
Here, the page corresponding to the first web page data may be a main frame page or a sub frame page.
After rendering a page corresponding to the first web page data and displaying the page, the electronic device continuously monitors whether a dynamically inserted tag exists in the displayed page.
And under the condition that the dynamically inserted tag is detected in the displayed page and is the same as the set tag, representing that the data corresponding to the dynamically inserted tag is advertisement data, and at the moment, the electronic equipment abandons the creation of the DOM node corresponding to the dynamically inserted first tag.
And under the condition that the dynamically inserted tag detected in the displayed page is different from the set tag, representing that the data corresponding to the dynamically inserted tag is not advertisement data, at the moment, the electronic equipment creates a DOM node corresponding to the dynamically inserted tag and renders the DOM node based on the DOM node corresponding to the dynamically inserted tag, so that the webpage element corresponding to the DOM node corresponding to the dynamically inserted tag is displayed. Before rendering is carried out on the DOM node corresponding to the dynamically inserted tag, the DOM node containing the advertisement data in the DOM node corresponding to the dynamically inserted tag can be removed by executing the first script.
In the scheme provided by this embodiment, after the corresponding page is displayed, the first tag containing the advertisement data dynamically inserted into the page can be accurately identified, so that creation of a DOM node corresponding to the first tag is abandoned, and the advertisement data dynamically inserted into the displayed page can be accurately intercepted.
Fig. 4 is a schematic diagram illustrating an implementation flow of a web page loading method according to another embodiment of the present application, and referring to fig. 4, on the basis of the embodiment corresponding to fig. 3, the web page loading method further includes:
s107: reporting the related information of the first label to the server; and the related information of the first label is used for the server to update the first script.
Here, when the electronic device determines the first tag, the electronic device reports the related information of the first tag to the server, so that the server updates the first script based on the related information of the first tag.
Wherein the related information of the first tag comprises at least one of the following:
a webpage element corresponding to the first label;
the style corresponding to the first label;
a frameset tag corresponding to the first tag;
a subframe tag corresponding to the first tag;
the corresponding inserting position of the first label.
In the solution provided in this embodiment, the electronic device reports the determined related information of the first tag to the server, and the server may update the first script stored in the server based on the related information of the first tag reported by the electronic device, so that the first script may be continuously updated, and the electronic device may identify the advertisement data in the webpage data more accurately and effectively by executing the updated first script.
Fig. 5 shows a flowchart of an implementation of injecting a first script according to an embodiment of the present application. Referring to fig. 5, the injecting the first script into the first webpage data includes:
s501: searching a subframe tag corresponding to the first webpage data in a set white list; wherein the set white list comprises at least one subframe tag.
And under the condition that the first webpage data represent webpage data under a subframe page, the electronic equipment searches subframe tags which are the same as the subframe tags corresponding to the first webpage data in a set white list based on the subframe tags corresponding to the first webpage data.
And under the condition that the subframe tags which are the same as the subframe tags corresponding to the first webpage data are found in the set white list, representing that the first script is not required to be executed, and thus carrying out advertisement removing operation on the first webpage data. At this time, the first script does not need to be injected into the first web page data.
And in the case that the subframe tag identical to the subframe tag corresponding to the first webpage data is not found in the set white list, representing that the first script needs to be executed, and executing S502.
S502: and under the condition that the subframe tag corresponding to the first webpage data is not found in the set white list, injecting a first script into the first webpage data.
In an embodiment, the electronic device may execute S501 to S502 when the second tag in the first webpage data is screened out. The second label is a different label than the set label.
In the scheme provided by this embodiment, whether the subframe tag corresponding to the first webpage data can be found in the set white list is determined by setting the white list, so as to determine whether the first script needs to be injected into the first webpage data, and thus the advertisement removal requirement of the corresponding page can be accurately determined. Under the condition that the subframe tag corresponding to the first webpage data is found in the set white list, the first script is not injected into the first webpage data, so that the data processing load of the electronic equipment can be reduced, and the advertisement in the first webpage data is prevented from being deleted by mistake.
As another embodiment of the present application, the injecting the first script into the first webpage data includes:
reading the first script from the inner core of the browser, and injecting the read first script into the first webpage data; and the first script is saved into the kernel of the browser when the browser is started and initialized.
Here, in the case of starting the kernel of the browser, the first script is read from the kernel of the browser, and the read first script is injected into the first web page data.
In the scheme provided by this embodiment, the first script may be directly read from the kernel of the browser, so that the first script is injected into the first webpage data, and the first script does not need to be acquired from the local database each time the webpage data is loaded, which may reduce the time and resources consumed by acquiring the first script and accelerate the webpage display speed.
In an embodiment, fig. 6 shows a flowchart of an implementation of saving a first script according to an embodiment of the present application. Referring to fig. 6, the web page loading method further includes:
s601: when the browser is started, whether the pre-cached first script is invalid is determined based on a timestamp of the pre-cached first script.
When a browser in the electronic equipment is started, reading a timestamp of a first script cached in advance, and determining whether the timestamp is invalid; when the timestamp is not invalid, representing that the pre-cached first script is not invalid, and executing S602; when the timestamp fails, the first script cached in advance is characterized to be failed, and S603 is executed.
The electronic device may also determine whether the pre-cached first script is stale based on the expiration date of the first script and the timestamp of the first script. When the pre-cached first script is not invalid, executing S602; when the first script cached in advance is invalid, S603 is executed.
S602: and under the condition that the pre-cached first script is not invalid and the browser initialization is completed, saving the pre-cached first script to a kernel of the browser.
Here, when the timestamp of the first script cached in advance is not expired and the browser initialization is completed, the first script is read from the corresponding cache area, and the read first script is saved in the kernel of the browser.
S603: and under the condition that the pre-cached first script is invalid, downloading the first script from the server, and saving the downloaded first script in a kernel of the browser when the browser initialization is completed.
Under the condition that the pre-cached first script is invalid, the electronic equipment downloads the latest first script from the server, caches the downloaded first script and updates the timestamp of the first script; and saving the downloaded first script to the kernel of the browser when the browser initialization is completed, so as to update the first script.
In the scheme provided by this embodiment, whether the first script cached in advance is invalid is determined by the timestamp of the first script, and the first script cached in advance is stored in the browser kernel under the condition that the first script cached in advance is not invalid, and the latest first script is downloaded from the server and the downloaded first script is stored in the browser kernel under the condition that the first script cached in advance is invalid.
As another embodiment of the present application, the injecting the first script into the first webpage data further includes:
injecting a first script into the first web page data before a kernel of the browser is started.
In the solution provided in this embodiment, before the kernel of the browser is started, the first script is injected into the first web page data, instead of injecting the first script into the first web page data after the first DOM tree corresponding to the first web page data is obtained through parsing, and the first script is injected into the first web page data in advance, so that the waiting time required for removing a DOM node containing advertisement data in the first DOM tree can be reduced, and the web page loading speed is increased.
Fig. 7 is a schematic diagram illustrating an implementation flow of a web page loading method according to an embodiment of the present application, and referring to fig. 7, the web page loading method includes:
s701: and receiving first webpage data sent by a server.
S702: and judging whether the first webpage data represent webpage data under the subframe page or not.
Here, when the first web page data represents web page data under a subframe page, S703 to S710 are executed; executing S711 and S704 when the first webpage data represents the webpage data under the main frame page; alternatively, S711 and S707 to S710 are executed.
S703: and under the condition that the first webpage data represent the webpage data under the subframe page, judging whether a first label in the first webpage data is the same as a set label or not.
Here, when the first web page data is analyzed and the first DOM tree corresponding to the first web page data is generated, it is determined whether the currently analyzed first tag is the same as the set tag.
If the first tag in the first webpage data is the same as the setting tag, S704 is executed. If the first tag in the first webpage data is not the same as the setting tag, S705 is executed.
S704: and under the condition that the first tag in the first webpage data is the same as the set tag, abandoning to create a DOM node corresponding to the first tag in the first webpage data.
S705: and under the condition that the first label in the first webpage data is different from the set label, judging whether the first webpage data needs to remove the first node or not.
Here, whether the first page data needs to remove the first node is determined by determining whether the subframe tag corresponding to the first page data can be found in the set white list. The first node characterizes a DOM node containing advertisement data.
Wherein, when the subframe tag corresponding to the first webpage data is not found in the set white list, the first node of the first webpage data needs to be removed, and S707 is executed; and under the condition that the subframe tag corresponding to the first webpage data is found in the set white list, representing the first webpage data without removing the first node, and executing S706.
S706: and rendering a page based on the first DOM tree corresponding to the first webpage data.
S707: injecting a first script into the first web page data.
S708: removing a first node in a DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data.
Here, please refer to the related description in S103 for the implementation process of S708, which is not described herein.
S709: and rendering the page based on the second DOM tree.
Here, please refer to the related description in S104 for the implementation process of S709, which is not described herein.
After performing S709, S710 is performed.
S710: and after the page corresponding to the first webpage data is rendered, under the condition that the dynamically inserted first label is detected in the page, abandoning to create a DOM node corresponding to the dynamically inserted first label.
S711: and under the condition that the first webpage data represent the webpage data under the main frame page, judging whether a first label in the first webpage data is the same as a set label or not.
If the first tag in the first webpage data is the same as the setting tag, S704 is executed. And executing S707 to S710 when the first label in the first webpage data is different from the setting label.
In the solution provided in this embodiment, under the condition that the first tag in the received first webpage data is the same as the set tag, the creation of the DOM node corresponding to the first tag in the first webpage data is abandoned, so that the number of DOM nodes corresponding to the first webpage data can be reduced, the time consumed by subsequently searching for the first node is reduced, and the speed of displaying the webpage is increased. Under the condition that the first tag in the first webpage data is different from the set tag, whether the subframe tag corresponding to the first webpage data can be found in the set white list or not is judged, whether the first script needs to be injected into the first webpage data or not is determined, the advertisement removing requirement of the corresponding page can be accurately determined, and under the condition that the subframe tag corresponding to the first webpage data is found in the set white list, the first script is not injected into the first webpage data, so that the advertisement in the first webpage data is prevented from being deleted by mistake. And when the subframe tag corresponding to the first webpage data is not found in the set white list, injecting the first script into the first webpage data, removing a first node in a first Document Object Model (DOM) tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree, and rendering the page based on the second DOM tree. By executing the first script injected into the first web page data, the advertisement data in the first web page data can be accurately removed. Because the second DOM tree is obtained after the DOM nodes containing the advertisement data in the first DOM tree are removed by executing the first script, the DOM nodes corresponding to the first tag do not exist in the first DOM tree, the DOM nodes containing the advertisement data do not exist in the second DOM tree, all the advertisement data in the first webpage data are removed before the page is rendered based on the second DOM tree, and the advertisement flash does not occur in the process of rendering the page.
In order to implement the method of the embodiment of the present application, an embodiment of the present application further provides a web page loading apparatus, which is disposed on an electronic device. As shown in fig. 8, the web page loading apparatus includes:
a receiving unit 81, configured to receive first webpage data sent by a server;
an injecting unit 82, configured to inject a first script into the first webpage data when the first webpage data represents webpage data under a subframe page;
the advertisement removing unit 83 is configured to remove a first node in a first DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data, so as to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data;
a rendering unit 84 for rendering a page based on the second DOM tree.
In one embodiment, the web page loading apparatus further includes:
the node creating unit is used for giving up creating a DOM node corresponding to a first label in the first webpage data when generating a first DOM tree corresponding to the first webpage data; wherein the content of the first and second substances,
the first label is the same as the set label; the content under the set label is characterized as an advertisement.
In an embodiment, the node creating unit is further configured to:
and after the page corresponding to the first webpage data is rendered, under the condition that the dynamically inserted first label is detected in the page, abandoning to create a DOM node corresponding to the dynamically inserted first label.
In one embodiment, the injection unit 82 is configured to:
searching a subframe tag corresponding to the first webpage data in a set white list;
under the condition that the subframe tag corresponding to the first webpage data is not found in the set white list, injecting a first script into the first webpage data; wherein the content of the first and second substances,
the set white list comprises at least one subframe tag.
In one embodiment, the injection unit 82 is configured to:
reading the first script from the inner core of the browser, and injecting the read first script into the first webpage data; wherein the content of the first and second substances,
and the first script is saved in the kernel of the browser when the browser is started and initialized.
In one embodiment, the web page loading apparatus further includes:
the determining unit is used for determining whether the pre-cached first script is invalid or not based on the timestamp of the pre-cached first script when the browser is started;
the saving unit is used for saving the pre-cached first script to a kernel of the browser under the condition that the pre-cached first script is not invalid and the browser initialization is completed;
and the downloading unit is used for downloading the first script from the server under the condition that the pre-cached first script is invalid, and storing the downloaded first script into the kernel of the browser when the browser is initialized.
In practical applications, the receiving unit 81 and the downloading unit may be implemented by a communication interface in the web page loading apparatus, the injecting unit 82, the advertisement removing unit 83, the rendering unit 84, the node creating unit, the determining unit and the storing unit may be implemented by a processor in the web page loading apparatus, and the downloading unit may be implemented by a communication interface and a processor in the web page loading apparatus. Of course, the processor needs to run the program stored in the memory to realize the functions of the above-described program modules.
It should be noted that: in the above embodiment, when loading a web page, the web page loading apparatus is described by taking only the division of the program modules as an example, and in practical applications, the processing may be distributed to different program modules according to needs, that is, the internal structure of the web page loading apparatus is divided into different program modules to complete all or part of the processing described above. In addition, the web page loading device and the web page loading method provided by the above embodiments belong to the same concept, and specific implementation processes thereof are described in the method embodiments in detail and are not described herein again.
Based on the hardware implementation of the program module, in order to implement the method of the embodiment of the present application, an embodiment of the present application further provides an electronic device. Fig. 9 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present application, and as shown in fig. 9, the electronic device includes:
a communication interface 1 capable of information interaction with other devices such as a server and the like;
and the processor 2 is connected with the communication interface 1 to realize information interaction with other equipment, and is used for executing the webpage loading method provided by one or more technical schemes when running a computer program. And the computer program is stored on the memory 3.
In practice, of course, the various components in the electronic device are coupled together by the bus system 4. It will be appreciated that the bus system 4 is used to enable connection communication between these components. The bus system 4 comprises, in addition to a data bus, a power bus, a control bus and a status signal bus. For the sake of clarity, however, the various buses are labeled as bus system 4 in fig. 9.
The memory 3 in the embodiment of the present application is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program for operating on an electronic device.
It will be appreciated that the memory 3 may be either volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. Among them, the nonvolatile Memory may be a Read Only Memory (ROM), a Programmable Read Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a magnetic random access Memory (FRAM), a Flash Memory (Flash Memory), a magnetic surface Memory, an optical disk, or a Compact Disc Read-Only Memory (CD-ROM); the magnetic surface storage may be disk storage or tape storage. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of illustration and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), Enhanced Synchronous Dynamic Random Access Memory (Enhanced Synchronous Dynamic Random Access Memory), Synchronous linked Dynamic Random Access Memory (DRAM, Synchronous Link Dynamic Random Access Memory), Direct Memory (DRmb Random Access Memory). The memory 3 described in the embodiments of the present application is intended to comprise, without being limited to, these and any other suitable types of memory.
The method disclosed in the above embodiment of the present application may be applied to the processor 2, or implemented by the processor 2. The processor 2 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 2. The processor 2 described above may be a general purpose processor, a DSP, or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor 2 may implement or perform the methods, steps and logic blocks disclosed in the embodiments of the present application. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium located in the memory 3, and the processor 2 reads the program in the memory 3 and in combination with its hardware performs the steps of the aforementioned method.
When the processor 2 executes the program, the corresponding processes in the methods according to the embodiments of the present application are realized, and for brevity, are not described herein again.
In an exemplary embodiment, the present application further provides a storage medium, i.e. a computer storage medium, specifically a computer readable storage medium, for example, including a memory 3 storing a computer program, which can be executed by a processor 2 to implement the steps of the foregoing method. The computer readable storage medium may be Memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface Memory, optical disk, or CD-ROM.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described device embodiments are merely illustrative, for example, the division of the unit is only a logical functional division, and there may be other division ways in actual implementation, such as: multiple units or components may be combined, or may be integrated into another system, or some features may be omitted, or not implemented. In addition, the coupling, direct coupling or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between the devices or units may be electrical, mechanical or other forms.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed on a plurality of network units; some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, all functional units in the embodiments of the present application may be integrated into one processing module, or each unit may be separately regarded as one unit, or two or more units may be integrated into one unit; the integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: a mobile storage device, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The technical means described in the embodiments of the present application may be arbitrarily combined without conflict.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (11)

1. A webpage loading method is characterized by comprising the following steps:
receiving first webpage data issued by a server;
under the condition that the first webpage data represent webpage data under a subframe page, injecting a first script into the first webpage data;
removing a first node in a DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data;
and rendering the page based on the second DOM tree.
2. The method of claim 1, further comprising:
when a first DOM tree corresponding to the first webpage data is generated, abandoning to create a DOM node corresponding to a first label in the first webpage data; wherein the content of the first and second substances,
the first label is the same as the set label; the content under the set label is characterized as an advertisement.
3. The method of claim 2, further comprising:
and after the page corresponding to the first webpage data is rendered, under the condition that the dynamically inserted first label is detected in the page, abandoning to create a DOM node corresponding to the dynamically inserted first label.
4. The method of claim 1, wherein the injecting the first script into the first web page data comprises:
searching a subframe tag corresponding to the first webpage data in a set white list;
under the condition that the subframe tag corresponding to the first webpage data is not found in the set white list, injecting a first script into the first webpage data; wherein the content of the first and second substances,
the set white list comprises at least one subframe tag.
5. The method of claim 1, wherein the injecting the first script into the first web page data comprises:
reading the first script from the inner core of the browser, and injecting the read first script into the first webpage data; wherein the content of the first and second substances,
and the first script is saved in the kernel of the browser when the browser is started and initialized.
6. The method of claim 5, further comprising:
when the browser is started, determining whether a pre-cached first script is invalid or not based on a timestamp of the pre-cached first script;
under the condition that the pre-cached first script is not invalid and the browser initialization is completed, saving the pre-cached first script to a kernel of the browser;
and under the condition that the pre-cached first script is invalid, downloading the first script from the server, and saving the downloaded first script in a kernel of the browser when the browser initialization is completed.
7. The method of claim 1, wherein the injecting the first script into the first web page data further comprises:
injecting a first script into the first web page data before a kernel of the browser is started.
8. The method of claim 2 or 3, further comprising:
reporting the related information of the first label to the server; and the related information of the first label is used for the server to update the first script.
9. A web page loading apparatus, comprising:
the receiving unit is used for receiving first webpage data issued by the server;
the injection unit is used for injecting a first script into the first webpage data under the condition that the first webpage data represent the webpage data under the subframe page;
the advertisement removing unit is used for removing a first node in a first DOM tree corresponding to the first webpage data by executing the first script injected into the first webpage data to obtain a second DOM tree; the first script is used for deleting a first node in the DOM tree; the first node represents a DOM node containing advertisement data;
and the rendering unit is used for rendering the page based on the second DOM tree.
10. An electronic device, comprising: a processor and a memory for storing a computer program capable of running on the processor,
wherein the processor is configured to execute the steps of the web page loading method according to any one of claims 1 to 8 when running the computer program.
11. A storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the web page loading method of any one of claims 1 to 8.
CN202010994240.3A 2020-09-21 2020-09-21 Webpage loading method and device and electronic equipment Pending CN112099875A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010994240.3A CN112099875A (en) 2020-09-21 2020-09-21 Webpage loading method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010994240.3A CN112099875A (en) 2020-09-21 2020-09-21 Webpage loading method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN112099875A true CN112099875A (en) 2020-12-18

Family

ID=73754770

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010994240.3A Pending CN112099875A (en) 2020-09-21 2020-09-21 Webpage loading method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN112099875A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110093342A1 (en) * 2007-09-13 2011-04-21 Robert Ennals Location-based filtering and advertising enhancements for merged browsing of network contents
CN104731824A (en) * 2013-12-24 2015-06-24 腾讯科技(深圳)有限公司 Picture display method and picture display device
CN108062324A (en) * 2016-11-08 2018-05-22 广州市动景计算机科技有限公司 Advertisement filter method, apparatus and user terminal
CN109684570A (en) * 2018-12-27 2019-04-26 北京字节跳动网络技术有限公司 Web information processing method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110093342A1 (en) * 2007-09-13 2011-04-21 Robert Ennals Location-based filtering and advertising enhancements for merged browsing of network contents
CN104731824A (en) * 2013-12-24 2015-06-24 腾讯科技(深圳)有限公司 Picture display method and picture display device
CN108062324A (en) * 2016-11-08 2018-05-22 广州市动景计算机科技有限公司 Advertisement filter method, apparatus and user terminal
CN109684570A (en) * 2018-12-27 2019-04-26 北京字节跳动网络技术有限公司 Web information processing method and device

Similar Documents

Publication Publication Date Title
CN109508191B (en) Code generation method and system
US6470349B1 (en) Server-side scripting language and programming tool
CN102722563B (en) Method and device for displaying page
CN106294658B (en) Webpage quick display method and device
US9195773B2 (en) Structure-based adaptive document caching
US8225192B2 (en) Extensible cache-safe links to files in a web page
US20060020693A1 (en) Data optimization
US20170199850A1 (en) Method and system to decrease page load time by leveraging network latency
JP2001503537A (en) Identify changed data in online data repositories
US20100023690A1 (en) Caching dynamic contents and using a replacement operation to reduce the creation/deletion time associated with html elements
CN110321177B (en) Mobile application localized loading method and device and electronic equipment
US20150302110A1 (en) Decoupling front end and back end pages using tags
CN104375808B (en) interface display method and device
MX2008011058A (en) Rss data-processing object.
CN106649395A (en) Webpage updating method and apparatus
CN110647700A (en) Page resource loading method and device, computer equipment and storage medium
CN111241793B (en) Method, system and medium for resolving rich text editor content to render to native client
CN112637361B (en) Page proxy method, device, electronic equipment and storage medium
WO2015062292A1 (en) Page layout method and system
CN108920691B (en) Front-end static resource management method and device, computer equipment and storage medium
US7069292B2 (en) Automatic display method and apparatus for update information, and medium storing program for the method
CN114021042A (en) Webpage content extraction method and device, computer equipment and storage medium
CN104915404A (en) Method and device for accessing invalid website
JP2008158589A (en) Updated information notification device, and updated information notification program
JP5063877B2 (en) Information processing apparatus and computer program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination