Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for collecting printer network information, and an electronic device, which can conveniently collect printer Web information.
In a first aspect, an embodiment of the present invention provides a method for acquiring network information of a printer, including:
logging in a login page of the printer network service, and acquiring login information and a main page link;
and acquiring page information of the printer network service according to the main page link.
With reference to the first aspect, in a first implementable manner of the first aspect, the acquiring page information of the printer web service according to the home page link includes:
generating a page link address list including the main page link address;
requesting a page corresponding to a page link address in the page link address list;
acquiring page information of a return page;
extracting a sub-page link address from the currently acquired page information;
judging whether the currently extracted sub-page link address exists in the page link address list or not;
and if the currently extracted sub-page link address does not exist in the page link address list, adding the new link address into the page link address list.
With reference to the first implementable manner of the first aspect, in a second implementable manner of the first aspect, the obtaining page information of the return page includes:
judging whether the returned page is a dynamic page or not;
if the return page is a dynamic page, dynamically acquiring page frame information of the return page;
requesting dynamic page information according to the currently acquired page frame information;
and acquiring page information from the dynamic page after the dynamic page is loaded.
With reference to the first aspect, in a third implementable manner of the first aspect, the logging in the login page of the printer network service, acquiring login information and a home page link, includes:
receiving a login page link address of a printer network service;
accessing the link address of the login page and opening the login page;
obtaining login page information and identifying the type of the login page;
sending the user account to the printer network service for login verification in a request mode corresponding to the login page type;
receiving a login success message returned by the printer network service;
and obtaining Cookie information generated by login and a main page link after login.
With reference to the first aspect, in a fourth implementable manner of the first aspect, after acquiring the page information of the printer network service, the method further includes:
creating a data storage folder corresponding to the brand and the model of the printer, and creating an external resource folder in the data storage folder;
generating page information of the printer network service into a page file, and storing the page file in the data storage folder;
searching the referenced external resource file link address from the page information of the printer network service;
and downloading the corresponding external resource file and storing the external resource file into the external resource folder according to the searched external resource file link address.
In a second aspect, an embodiment of the present invention provides a printer network information acquisition apparatus, including:
the login module is used for logging in a login page of the printer network service and acquiring login information and a main page link;
and the information acquisition module is used for acquiring the page information of the printer network service according to the main page link.
With reference to the second aspect, in a first implementable manner of the second aspect, the information obtaining module includes:
the list generation submodule is used for generating a page link address list comprising the main page link address;
the request submodule is used for requesting a page corresponding to a page link address in the page link address list;
the page information acquisition submodule is used for acquiring the page information of the returned page requested by the request submodule;
the information extraction submodule is used for extracting a subpage link address from the currently acquired page information;
the judging submodule is used for judging whether the currently extracted sub-page link address exists in the page link address list or not;
and the list updating submodule is used for adding the currently extracted sub-page link address into the page link address list when the judgment result of the judging submodule is negative.
With reference to the first implementable manner of the second aspect, in a second implementable manner of the second aspect, the page information obtaining sub-module includes:
the judging unit is used for judging whether the return page is a dynamic page or not;
the page frame acquiring unit is used for dynamically acquiring the page frame information of the returned page when the judgment result of the judging unit is yes;
the request unit is used for requesting dynamic page information according to the page frame information currently acquired by the page frame acquisition unit;
and the page information acquisition unit is used for acquiring the page information from the dynamic page after the dynamic page requested by the request unit is loaded.
With reference to the second aspect, in a third implementable manner of the second aspect, the login module includes:
the input submodule is used for receiving a login page link address of the printer network service;
the access submodule is used for accessing the link address of the login page and opening the login page;
the page type identification submodule is used for acquiring login page information and identifying the type of the login page;
the sending submodule is used for sending the user account to the printer network service for login verification in a request mode corresponding to the login page type;
the receiving submodule is used for receiving a login success message returned by the printer network service;
and the login information acquisition submodule is used for acquiring the Cookie information generated by login and the link of the main page after login.
With reference to the second aspect, in a fourth possible implementation manner of the second aspect, the apparatus further includes:
the system comprises a folder creating module, a data saving folder creating module and a resource creating module, wherein the folder creating module is used for creating a data saving folder corresponding to the brand and the model of the printer and creating an external resource folder in the data saving folder;
the page file storage module is used for generating the page information of the printer network service acquired by the information acquisition module into a page file and storing the page file in the data storage folder;
the searching module is used for searching the referred external resource file link address from the page information of the printer network service acquired by the information acquisition module;
and the downloading module is used for downloading the corresponding external resource file and storing the external resource file into the external resource folder according to the external resource file link address searched by the searching module.
In a third aspect, an embodiment of the present invention provides an electronic device, where the electronic device includes: the device comprises a shell, a processor, a memory, a circuit board and a power circuit, wherein the circuit board is arranged in a space enclosed by the shell, and the processor and the memory are arranged on the circuit board; a power supply circuit for supplying power to each circuit or device of the electronic apparatus; the memory is used for storing executable program codes; the processor reads the executable program codes stored in the memory to run programs corresponding to the executable program codes, and is used for executing the printer network information acquisition method in any one of the foregoing embodiments.
According to the printer network information acquisition method, the printer network information acquisition device and the electronic equipment, page information returned by the printer Web request is acquired by logging in a log-in page of the printer Web service, so that the printer Web information can be conveniently collected, and the printer network information acquisition method, the printer network information acquisition device and the electronic equipment are more real, accurate, detailed and reliable compared with other printer information sources. The printer link information can be retrieved according to the acquired page information, the page link and the information such as key texts, style sheets, JavaScript scripts and pictures in the page information are collected, a data base line database of detailed information of printers of various brands and models can be established, and basic data is accumulated for the development of related security application software and hardware of the printers in the next step. Along with the increase of the brand and the model of the printer of collection, can improve the printer and detect and the discernment and the support degree that the protection instrument printed to each brand and model, also can provide data support for the quick retrieval of printer function, interface.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a flowchart of a first embodiment of a method for acquiring network information of a printer according to the present invention, as shown in fig. 1, the method of this embodiment may include:
step S101, logging in a login page of the printer network service, and acquiring login information and a main page link;
in this embodiment, a user accesses a login page of a printer Web service to acquire login information and a home page link of the printer Web service. Preferably, as shown in fig. 2, the present step may specifically include the following steps S201 to S205:
step S201, receiving a login page link address of printer network service;
in this step, the user can directly input the login page link address of the printer Web service to be detected in the detection tool provided by the invention.
Step S202, accessing the link address of the login page and opening the login page;
step S203, obtaining login page information and identifying the type of the login page;
in this step, login page information of the printer is acquired, and the printer login page type (for example, Form or http basic) is intelligently determined.
Step S204, sending the user account to the printer network service for login verification in a request mode corresponding to the login page type;
in the step, the user fills in the printer Web administrator password, and if the user does not fill in the printer Web administrator password, the detection tool provided by the invention can retrieve the related default password list from the database according to the brand and the model of the printer to carry out adaptive login.
And step S205, receiving a login success message returned by the printer network service.
And S206, acquiring Cookie information generated by login and a main page link after login.
In this embodiment, if the user account logs in successfully, the printer network service returns Cookie information to the request end, returns a home page link to the request end, and obtains and temporarily stores the Cookie information and the home page link address of the printer network service.
And step S102, acquiring page information of the printer network service according to the main page link.
In this step, if the main page of the printer Web service is linked, the main page of the printer Web service can be opened, and all page information of the printer Web service is acquired after the main page is loaded. Here, the Web page information mainly includes: HTML, CSS style sheets, JS scripts, and data (some CSS style sheets, JS scripts are referenced in the page as a facade resource file and are not contained in the current page information).
In a preferred embodiment, as shown in FIG. 3, step 102 may include the steps of:
s301, generating a page link address list including the main page link address and temporarily storing the page link address list;
step S302, requesting a page corresponding to the Nth page link address in the page link address list;
the initial value of N is 1, and when the request is made, page link addresses which are not requested are requested from the page link address list according to the sequence from front to back. In the first execution of the method provided by the present invention, the printer Web service returns the home page upon starting to request the 1 st page link address in the page link address list, i.e. the home page link address stored in the page link address list in step 301.
Step S303, page information of a return page is obtained;
in this embodiment, if the step S302 requests the nth page link address in the page link address list, the step acquires and temporarily stores page information corresponding to the nth page link address.
As an optional embodiment, because the Web page has a static page and a dynamic page, and data of the dynamic page is requested back in multiple times, the method for obtaining page information of the returned page may include the following steps:
(1) judging whether the returned page is a dynamic page or not, and if the returned page is the dynamic page, dynamically acquiring page frame information of the returned page;
the method comprises the steps of obtaining page frame information according to a main page link, carrying out intelligent analysis on the page frame information, and judging whether the page type is an HTML (hypertext markup language) file, an XML (extensive makeup language) file, a CGI (common gateway interface) file and the like.
(2) Requesting dynamic page information according to the currently acquired page frame information;
in this step, a request is made for page dynamic information according to the parsed page frame information, for example: XML files, XSL files, JSON files, DAT files, etc.
(3) After the dynamic page is loaded, acquiring page information from the dynamic page;
(4) and if the returned page is a static page, directly acquiring page information from the static page and temporarily storing the page information.
Step S304, extracting a sub-page link address from the currently acquired page information;
in the step, the currently acquired page information is intelligently analyzed, the sub-page link address in the current page is identified and extracted, and the meaningless, cross-domain access and logout links are filtered, for example, 5 sub-page link addresses are finally extracted.
Step S305, judging whether the currently extracted sub-page link address exists in the page link address list or not; if yes, go to step S307, otherwise, go to step S306,
in this step, if the currently extracted sub-page link address has a record in the page link address list, it is not necessary to operate the currently extracted sub-page link address. This step can filter out duplicate link addresses that appear in different sub-pages under the main page link.
Step S306, adding the new link address into the page link address list;
in this step, if the sub-page link address extracted in step S304 does not exist in the page link address list, the currently extracted new link address without record is added to the page link address list and arranged at the end of the original page link address list.
In step S307, N is made N +1, and the process returns to step S302.
In this step, after adding 1 to the value of N, the process returns to step S302 to request the page corresponding to the nth page link address in the page link address list.
In the embodiment shown in fig. 3, a page link address list corresponding to the current printer is generated, page information is obtained by linking addresses in the page link address list one by one in a recursive manner, repeated links are filtered, and all the obtained page information is temporarily stored until a main page of the printer Web service and all sub-page links and page information below the main page are obtained.
Fig. 4 is a flowchart of a second embodiment of a method for acquiring printer network information according to the present invention, where the method of this embodiment is further configured to store collected printer network information on the basis of the first embodiment, and as shown in fig. 4, the method of this embodiment may include:
step S401, logging in a login page of the printer network service, and acquiring login information and a main page link.
In this embodiment, the specific implementation method of step S401 is similar to that of step S101, and is not described herein again.
And step S402, acquiring page information of the printer network service according to the main page link.
In this embodiment, the specific implementation method of step S402 is similar to that of step S102, and is not described herein again.
Step S403, creating a data saving folder corresponding to the printer brand and model, and creating an external resource folder in the data saving folder.
In this embodiment, a data saving folder corresponding to the current printer brand and model is created in the database, and an external resource folder is created in the data saving folder. The data saving folder is used for storing acquired network information data (including login information of printer network service, a page link address list, page information and the like) of the printer, and the external resource folder is used for saving external resource files corresponding to external resource links recorded in a main page and all sub-pages of the current printer.
And S404, generating page information of the printer network service into a page file, and storing the page file in the data storage folder.
Step S405, searching the referenced external resource file link address from the page information of the printer network service.
As mentioned above, the Web page information mainly includes: HTML, CSS style sheets, JS scripts and data, and some CSS style sheets and JS scripts are referenced appearance resource files in the page and are not contained in the current page information, and the step searches for the link addresses of the referenced resource files such as the CSS style sheets, the JavaScript scripts and the pictures except the HTML.
Step S406, downloading the corresponding external resource file according to the searched external resource file link address and storing the external resource file in the external resource folder.
In the second embodiment of the invention, the network service of the printer is logged in to obtain the login information and the main page link, the main page is linked through the main page, all the page information of the network service of the printer is obtained, all the page information is generated into the page file for storage, the link address of the external resource file is obtained from the page information, and the external resource file is downloaded and stored. The printer information can be quickly acquired and collected without any physical connection to the printer. The intelligent network connection printer has the advantages that page analysis and data acquisition and storage are intelligently carried out on all printers supporting network connection, information data storage is carried out according to the brands and the models of the printers during storage, and a user can conveniently extract and arrange corresponding data packets of the printers of all brands and models according to collected data.
Fig. 5 is a flowchart of a third embodiment of the method for acquiring network information of a printer according to the present invention, and the method of the present embodiment is further configured to save data in the data saving folder in a database and generate a corresponding database script on the basis of the second embodiment. As shown in fig. 5, the method of this embodiment may include:
step S501, logging in a login page of the printer network service, and acquiring login information and a main page link.
And step S502, acquiring page information of the printer network service according to the main page link.
Step S503, creating a data saving folder corresponding to the brand and the model of the printer, and creating an external resource folder in the data saving folder.
Step S504, generating the page information of the printer network service into a page file, and storing the page file in the data storage folder.
And step S505, searching the referenced external resource file link address from the page information of the printer network service.
And S506, downloading the corresponding external resource file according to the searched external resource file link address and storing the external resource file in the external resource folder.
In this embodiment, the specific implementation method of steps S501 to S506 is similar to that of steps S401 to S406, and is not described herein again.
And step S507, storing the login information, the page link address list and the page information of the printer network service into a database.
Step S508, a database script file related to the login information, the page link address list, and the page information of the printer web service saved this time is generated.
For example: and generating an SQL database script file related to the login information, the page link address list and the page information of the printer network service saved at this time.
And step S509, saving the database script file into a data saving folder.
In the third embodiment, the established printer detailed information database can provide data support for the rapid retrieval of functions and interfaces provided by the printer.
In an alternative embodiment, after step S509 in fig. 5, the method may further include: the method comprises the steps of encrypting the data storage folder according to a preset encryption method, compressing the encrypted file, hiding the extension of the obtained compressed file, and assigning a new extension for the compressed file. The embodiment further encrypts the stored data file and disguises the data file through a packer, so that the safety of the stored printer network information can be further improved.
In an alternative embodiment, before logging in to the login page of the printer network service, the brand and model of the current printer may be adapted, as shown in fig. 6, and the method for adapting the brand and model of the printer may include the following steps:
step S601, receiving a printer brand model adaptation request;
step S602, providing a pre-stored printer brand and model list;
step S603, receiving a selection of a printer brand and model in the printer brand and model list, or receiving a newly added printer brand and model and storing the newly added printer brand and model in the printer brand and model list.
In this embodiment, a user initiates a request for adapting a brand and a model of a printer, and provides a pre-stored list of the brand and the model of the printer to a current user, and if the list of the brand and the model of the printer is provided with a brand and a model of the printer that the current user wants to acquire information, the user directly selects the brand and the model of the printer from the list of the brand and the model of the printer, and if the list of the brand and the model of the printer does not have a brand and a model that the current user wants to acquire information, the user can manually input and add a new brand and a new model of the printer, and after receiving the brand and the model of the printer newly added by the user, the user stores the brand and the new.
After adapting the brand and model of the printer, the method provided by the invention can firstly inquire whether the database has the stored data corresponding to the brand and model of the printer, and if so, can directly provide the stored network information data of the printer of the brand and model to the user. And if the database does not contain the stored data corresponding to the brand and the model of the printer, starting to execute the step of logging in the login page of the printer network service and the subsequent steps so as to collect the network information of the current printer, wherein a data storage folder corresponding to the brand and the model of the printer directly added by the user at this time is created in the step S403. Of course, when the database is queried to have the stored data corresponding to the brand and model of the printer, the user may also be provided with relevant information, such as information about the acquisition and storage time of the data, and if the user does not want to use the previously stored data, the new network information data of the printer corresponding to the brand and model of the printer may also be acquired again by using the method of the fourth or fifth embodiment. Or, according to a preset updating time period, reminding a user to regularly adopt the method provided by the invention to collect network information data of printers of various brands and models, and updating corresponding data in the database.
For example, a "three high" (high value, high threat, high confrontation) customer needs to purchase a printer for confidential use and support a particular function. By adopting the method provided by the embodiment of the invention, the corresponding printer brand and model can be quickly searched in the collected printer detailed information base, the safety of the printer is evaluated by combining with subsequently developed detection and protection products, and the optimal scheme selected by the printer is given to a client.
Corresponding to the method provided by the invention, the invention also provides a printer network information acquisition device. Fig. 7 is a schematic structural diagram of a first embodiment of a network information acquisition device of a printer according to the present invention, and as shown in fig. 7, the device of the present embodiment may include:
the login module 11 is used for logging in a login page of the printer network service and acquiring login information and a main page link;
and the information acquisition module 12 is configured to acquire page information of the printer network service according to the main page link.
The apparatus of this embodiment may be used to implement the technical solution of the method embodiment shown in fig. 1, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 8 is a schematic structural diagram of the information obtaining module 12 in fig. 7, and as shown in fig. 8, the information obtaining module 12 may include:
a list generating submodule 121 configured to generate a page link address list including the main page link address;
the request submodule 122 is configured to request a page corresponding to a page link address in the page link address list;
the page information obtaining sub-module 123 is configured to obtain page information of a returned page requested by the request sub-module 122;
an information extraction submodule 124, configured to extract a sub-page link address from currently acquired page information;
a judging submodule 125, configured to judge whether the currently extracted sub-page link address exists in the page link address list;
and the list updating sub-module 126 is configured to, if the determination result of the determining sub-module 125 is negative, add the currently extracted sub-page link address to the page link address list.
The apparatus of this embodiment may be used to implement the technical solution of the method embodiment shown in fig. 3, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 9 is a schematic structural diagram of the page information obtaining sub-module 123, and as shown in fig. 9, the page information obtaining sub-module 123 may include:
a judging unit 21 configured to judge whether the return page is a dynamic page;
a page frame obtaining unit 22, configured to, when the determination result of the determining unit 21 is yes, dynamically obtain page frame information of the returned page;
a request unit 23, configured to request dynamic page information according to the page frame information currently acquired by the page frame acquisition unit 22;
the page information obtaining unit 24 is configured to obtain page information from the dynamic page after the dynamic page requested by the requesting unit 23 is loaded, and is further configured to obtain page information from the current static page if the determination result of the determining unit 21 is negative.
Fig. 10 is a schematic structural diagram of the login module 11 in fig. 7, and as shown in fig. 10, the login module 11 may include:
an input sub-module 111 for receiving a login page link address of the printer web service;
the access submodule 112 is used for accessing the link address of the login page and opening the login page;
a page type identification submodule 113, configured to acquire login page information and identify a login page type;
a sending sub-module 114, configured to send a user account to the printer network service for login verification in a request manner corresponding to the login page type;
a receiving submodule 115, configured to receive a login success message returned by the printer web service;
and the login information acquisition submodule 116 is configured to acquire Cookie information generated by login and a link of the main page after the login.
The apparatus of this embodiment may be used to implement the technical solution of the method embodiment shown in fig. 2, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 11 is a schematic structural diagram of a second embodiment of a network information acquisition device of a printer according to the present invention, and as shown in fig. 11, the device of this embodiment may further include, on the basis of the structure of the device shown in fig. 7:
a folder creation module 13, configured to create a data saving folder corresponding to the brand and model of the printer, and create an external resource folder in the data saving folder;
a page file storage module 14, configured to generate the page information of the printer network service acquired by the information acquisition module 12 into a page file, and store the page file in the data saving folder;
a search module 15, configured to search for a referenced external resource file link address from the page information of the printer web service acquired by the information acquisition module 12;
and the downloading module 16 is configured to download the corresponding external resource file and store the external resource file in the external resource folder according to the link address of the external resource file found by the searching module 15.
The apparatus of this embodiment may be used to implement the technical solution of the method embodiment shown in fig. 4, and the implementation principle and the technical effect are similar, which are not described herein again.
Corresponding to the method for acquiring network information of a printer provided by the embodiment of the present invention, an embodiment of the present invention further provides an electronic device, fig. 12 is a schematic structural diagram of an embodiment of the electronic device of the present invention, and a flow of the embodiment shown in fig. 1 of the present invention may be implemented, and as shown in fig. 12, the electronic device may include: the device comprises a shell 31, a processor 32, a memory 33, a circuit board 34 and a power circuit 35, wherein the circuit board 34 is arranged inside a space enclosed by the shell 31, and the processor 32 and the memory 33 are arranged on the circuit board 34; a power supply circuit 35 for supplying power to each circuit or device of the electronic apparatus; the memory 33 is used for storing executable program codes; the processor 32 executes a program corresponding to the executable program code by reading the executable program code stored in the memory 33, for executing the printer network information acquisition method of any of the foregoing embodiments.
The above electronic devices exist in a variety of forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include: smart phones (e.g., iphones), multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra mobile personal computer device: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: PDA, MID, and UMPC devices, etc., such as ipads.
(3) A portable entertainment device: such devices can display and play multimedia content. This type of device comprises: audio and video playing modules (such as an iPod), handheld game consoles, electronic books, and intelligent toys and portable car navigation devices.
(4) A server: the device for providing the computing service comprises a processor, a hard disk, a memory, a system bus and the like, and the server is similar to a general computer architecture, but has higher requirements on processing capacity, stability, reliability, safety, expandability, manageability and the like because of the need of providing high-reliability service.
(5) And other electronic equipment with data interaction function.
The invention further provides a computer-readable storage medium, in which a computer program is stored, and the computer program is used for implementing the steps of the network information collection method of the printer in any one of the foregoing embodiments when being executed by a processor.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.