Automatic batch downloading method, device and equipment for platform reports and storage medium

Through the automated login and extraction rule parsing technology of the Selenium library, the problem of low efficiency in obtaining massive dynamic reports is solved, efficient batch downloading and report integrity verification are realized, and the efficiency and accuracy of data collection are improved.

CN118802883APending Publication Date: 2024-10-18SHANGHAI ENERGY CONSERVATION CENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410863507.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-29
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

Existing technology is difficult to efficiently obtain and download massive dynamically generated website data reports, especially reports in complex web page structures, resulting in a limited number of data reports.

Method used

By using the WebDriver interface of the Selenium library in the browser to realize automatic login, extract preset keywords and custom extraction rules, parse the web page structure, download target reports in batches, and use concurrency control and integrity verification mechanisms to improve the efficiency and accuracy of report acquisition. sex.

Benefits of technology

It enables efficient batch downloading of massive reports from complex websites, improves the quantity and efficiency of report acquisition, reduces human errors and login failure rates, and ensures the integrity and quality of reports.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118802883A_ABST
    Figure CN118802883A_ABST
Patent Text Reader

Abstract

The invention provides an automatic batch downloading method and device for platform reports, equipment and a storage medium, and relates to the technical field of automatic data processing, and the method comprises the following steps: opening a target website in a browser, and logging in a target webpage in the target website; opening a plurality of target sub-pages in the target webpage, and filling a search bar in each target sub-page with preset search content for searching to obtain a plurality of sub-page links; obtaining a preset keyword and a user-defined extraction rule; according to a preset keyword and a self-defined extraction rule, extracting an element corresponding to the target report from each sub-page link, and according to the element corresponding to the target report, determining a downloading link of the target report in each sub-page link; and downloading the target report according to the downloading link of the target report in each sub-page link, and storing the target report locally. The method has the technical effect that the number of the data reports obtained from the website is increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of automated data processing, and in particular to a method, device, equipment and storage medium for automated batch downloading of platform reports. Background Art

[0002] With the development of modern information technology, the amount of data on the Internet platform has increased dramatically. Various websites provide massive data reports, which often contain valuable information in the fields of business operations, scientific research, market analysis, etc. With the rapid increase in the amount of data, it has become particularly important to obtain this information effectively and efficiently.

[0003] With the development of automation technology, web crawlers and download managers are usually used to assist in downloading data reports provided by various websites on the Internet. However, the above methods can only handle static content and direct file downloads. For dynamically generated content and complex web page structures, the capabilities of these tools are significantly limited, resulting in a limited number of data reports obtained from the website. Summary of the invention

[0004] The present application provides a platform report automatic batch download method, device, equipment and storage medium for increasing the number of data reports obtained from a website.

[0005] In a first aspect, the present application provides a method for automated batch downloading of platform reports, the method comprising: opening a target website in a browser and logging in to a target web page in the target website; opening multiple target sub-pages in the target web page, and filling in preset search content in the search bar in each of the target sub-pages for searching, to obtain multiple sub-page links; obtaining preset keywords and custom extraction rules; extracting elements corresponding to a target report in each of the sub-page links according to the preset keywords and the custom extraction rules, and determining a download link for the target report in each of the sub-page links according to the elements corresponding to the target report; downloading the target report according to the download link for the target report in each of the sub-page links, and saving the target report locally.

[0006] By adopting the above technical solution, in order to realize the automatic batch download of reports, it is necessary to operate in a programmatic way. First, open the target website in the browser and enter the account and password to complete the login to access the report page that requires permission. After logging in, the program will pre-set keywords and extraction rules, find elements that meet the rules in the search results page, and parse to obtain the download address of the report. After the parsing is completed, the program can access these extracted download links in batches, and continuously download and save the report files locally. Through such an automated process, the number of data reports obtained from the website can be increased, and massive reports can be automatically downloaded in batches.

[0007] Optionally, opening the target website in a browser and logging into a target webpage in the target website includes: opening the target website in a browser through a WebDriver interface in a Selenium library; entering a user name and password in a login page of the target website to log into the target webpage.

[0008] By adopting the above technical solution, the program first calls WebDriver to open the login page of the target website, locates the account and password input box, and automatically fills in the preset account and password information. After submitting the login, Selenium will automatically handle the interaction of various elements in the login process. After completing this series of processes, the program passes the user verification and successfully logs in to the target website. Using Selenium automated method to realize login not only saves the time of manual operation, but also can accurately locate the page elements to avoid human errors in the login process. Compared with traditional manual login, the automated login process is more accurate and reliable, which greatly improves the efficiency of report data collection. Using Selenium, a mature automated testing tool, the program can smoothly execute the login process of the target website. With the program's automatic operation of page elements, the automation of the login link in the report collection task is realized, laying the foundation for the subsequent acquisition of confidential report data.

[0009] Optionally, after entering the user name and password in the login page of the target website, it also includes determining whether the current page has entered the target webpage of the target website; if the target webpage of the target website has not been entered, clearing the user name and password, and re-entering the user name and password in the login page; if the user name and password are re-entered a preset number of times in the login page, sending an error message to the operator's terminal device; if the target webpage of the target website has been entered, obtaining Cookies information of the current login status through the Cookie interface of Selenium, and storing the Cookies information; accessing the target webpage of the target website through the Get interface of Selenium, and loading the Cookies information into the browser.

[0010] By adopting the above technical solution, Selenium's page element recognition function determines whether the current page is the target web page. If the target page is not successfully entered, it means that the login failed. The program will clear the user name and password, and re-enter the preset number of times before judging. This cyclic verification can avoid errors in the login process. If continuous re-login fails, the program will automatically send a prompt message to the relevant personnel. Manual intervention can quickly solve login failures and reduce the failure rate of report collection tasks. If the final login is successful and enters the target page, Selenium is used to obtain the Cookies information of the current login status and store it. In this way, Cookies can be reused to directly access the target page without repeated login, which optimizes the process. When the target web page needs to be accessed later, the program directly uses Selenium's Get interface to send an access request and loads the stored Cookies information into the request, greatly improving the collection efficiency of the target website report.

[0011] Optionally, according to the preset keywords and the custom extraction rules, the elements corresponding to the target report are extracted from each of the sub-page links, and according to the elements corresponding to the target report, the download link of the target report in each of the sub-page links is determined, including: obtaining the DOM structure of each of the sub-page links; according to the preset keywords, searching for the first element corresponding to the target report in the DOM structure of each of the sub-page links; according to the custom extraction rules, filtering the first element to obtain the second element; according to the second element, constructing the information structure of the target report; according to the information structure of the target report, determining the download link of the target report in each of the sub-page links.

[0012] By adopting the above technical solution, the program obtains the DOM tree of the web page and searches for report-related elements in the tree structure based on keywords. These elements contain information such as the report name and format. The first round of search results are screened again according to the preset custom extraction rules. Then the complete information structure of the report is constructed based on these elements. Finally, the download address attribute of the report object is read to obtain the download link of the target report. After the process of page parsing, information extraction and screening, the available report download address is successfully located from the complex page. Such an automated parsing mechanism can effectively extract accurate report download links from massive search results, greatly improving the efficiency of report acquisition. Efficient collection from complex page structures to report download addresses is achieved.

[0013] Optionally, downloading the target report according to the download link of the target report in each sub-page link, and saving the target report locally, includes: obtaining system resources and network status; determining the maximum concurrency number of download tasks according to the system resources and the network dynamics, and downloading the target report according to the maximum concurrency number; when the target report is downloaded, saving the target report locally.

[0014] By adopting the above technical solution, after obtaining the download link of the target report, the program needs to download and save the report files pointed to by this batch of links locally. Since the number of reports may be very large, in order to control the download efficiency, it is necessary to optimize the number of concurrent downloads. The specific approach is to detect the current available system resource status, and also monitor the real-time status of the network to determine whether there is a delay or interruption. Based on this information, the program can calculate the maximum allowed number of concurrent downloads. Then, according to the optimal number of concurrent downloads, multiple threads are opened to download multiple report files at the same time. Controlling the number of concurrent downloads can make efficient use of network resources and system resources, and avoid overload affecting the download speed. After all reports are downloaded, the program will automatically store them in the specified local directory. It not only realizes high-speed batch download of reports, but also ensures the stability of the server and client.

[0015] Optionally, after saving the target report locally, the method further includes: verifying the integrity of the target report; if the integrity of the target report meets preset requirements, classifying the target report according to the content, type and business needs of the target report.

[0016] By adopting the above technical solution, after downloading and saving a large number of reports, it is necessary to verify their integrity and correctness. The algorithm verifies whether the content of each report is complete, and after verification, each report is automatically classified and stored in the relevant directory. Classified storage can facilitate the subsequent rapid retrieval of reports of the required type and subject, and improve the efficiency of analysis work. The automated mechanism of report verification and classification can standardize the massive reports after they are downloaded, filter out invalid reports, and effectively organize and store available reports. The automated process also reduces the probability of human errors.

[0017] Optionally, the target report is integrity verified, including: verifying the file name and file size value of the target report; matching the text information in the target report with the report samples stored in the database, and calculating the text similarity; if the file name and file size of the target report pass the verification and the text similarity is higher than a preset threshold, then the target report is judged to have passed the integrity verification.

[0018] By adopting the above technical solution, in order to ensure the validity of the report, the file name and file size value of the target report are verified, the text information in the target report is matched with the report samples stored in the database, and the text similarity is calculated. The damaged and incomplete reports can be effectively identified and excluded, ensuring the quality of the report for subsequent analysis and application.

[0019] In a second aspect, the present application provides an automatic batch downloading device for platform reports, the device comprising: a login module, a search module, an acquisition module, a generation module and a download module; wherein the login module is used to open a target website in a browser and log in to a target web page in the target website; the search module is used to open multiple target sub-pages in the target web page, and fill in a preset search content in the search bar in each of the target sub-pages for searching, and obtain multiple sub-page links; the acquisition module is used to obtain preset keywords and custom extraction rules; the generation module is used to extract elements corresponding to a target report in each of the sub-page links according to the preset keywords and the custom extraction rules, and determine the download link of the target report in each of the sub-page links according to the elements corresponding to the target report; the download module is used to download the target report according to the download link of the target report in each of the sub-page links, and save the target report locally.

[0020] By adopting the above technical solution, in order to realize the automatic batch download of reports, it is necessary to operate in a programmatic way. First, open the target website in the browser and enter the account and password to complete the login to access the report page that requires permission. After logging in, the program will pre-set keywords and extraction rules, find elements that meet the rules in the search results page, and parse to obtain the download address of the report. After the parsing is completed, the program can access these extracted download links in batches, and continuously download and save the report files locally. Through such an automated process, the number of data reports obtained from the website can be increased, and massive reports can be automatically downloaded in batches.

[0021] In the third aspect, the present application provides an electronic device, adopting the following technical solution: including a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes a computer program such as any of the above-mentioned platform report automated batch download methods.

[0022] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: storing a computer program that can be loaded by a processor and execute any of the above-mentioned platform report automated batch download methods.

[0023] In summary, the present application includes at least one of the following beneficial technical effects: 1. Automatically download massive reports in batches; 2. Effectively extract accurate report download links from massive search results, greatly improving the efficiency of report acquisition. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a flow chart of a method for automatically downloading platform reports in batches provided in an embodiment of the present application; Figure 2 It is a structural schematic diagram of a platform report automatic batch downloading device provided in an embodiment of the present application; Figure 3 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0025] Description of reference numerals: 1000, electronic device; 1001, processor; 1002, communication bus; 1003, user interface; 1004, network interface; 1005, memory. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.

[0027] In the description of the embodiments of the present application, words such as "illustrative", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "illustrative", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "illustrative", "for example" or "for example" is intended to present related concepts in a concrete way.

[0028] Figure 1 1 is a flow chart of a method for automatically downloading platform reports in batches provided in an embodiment of the present application. Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but the steps are not necessarily executed in the order indicated by the arrows; unless otherwise specified in this document, there is no strict order restriction for the execution of the steps, and the steps may be executed in other orders; and Figure 1At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0029] This application discloses a method for automatically downloading platform reports in batches, such as Figure 1 As shown, the method includes S101-S105.

[0030] S101, opening a target website in a browser and logging into a target webpage in the target website.

[0031] In one example, to achieve automated batch downloading of platform reports, you first need to programmatically log in to the target website to access the report. The WebDriver interface in the Selenium library can be used to programmatically control the browser, which provides browser automation functions such as opening websites, filling out forms, and clicking buttons.

[0032] Selenium is an open source web application testing tool that provides different components to support browser automation testing. Selenium is an open source testing tool for web application test automation. It supports multiple browsers including Chrome, Firefox, IE, etc.

[0033] Selenium can be run directly on the browser or can be bound to programming languages ​​such as Java and C#. Selenium can automatically control the browser and support operations such as opening and closing the browser, filling forms, clicking buttons, and page navigation. The main components of Selenium include WebDriver, Selenium IDE, SeleniumGrid, etc.

[0034] WebDriver is a core component of Selenium and is used to automate web browsers.

[0035] WebDriver interacts directly with the browser and can obtain the browser's Manipulate capability, thereby simulating user operations such as positioning, clicking, and inputting page elements. WebDriver provides a series of API interfaces in languages ​​such as Java, Python, and C#, which can be directly called to achieve browser automation.

[0036] Commonly used WebDriver interfaces include get(), find_element(), send_keys(), click(), etc., which are used for browser opening, element positioning, input, etc. WebDriver can implement cross-browser automated testing, such as ChromeDriver, FirefoxDriver, etc. are all implementations of WebDriver.

[0037] The specific implementation method is: first instantiate a WebDriver object to access the target website. Then access the login page URL of the target website through the get() method of the WebDriver object to open the login page of the target website in the browser. Then find the username input box and password input box elements of the login page, and fill in the preset username and password in the username and password input boxes through the send_keys() method; find the login button element, and complete the click operation of the login button through the click() method. Finally, determine whether the page source code or URL of the current page contains the characteristic information of the target web page to check whether the login is successful. If the login fails, the adding_cookie() method can be used to add the cookie information saved by the last successful login to achieve automatic re-login.

[0038] This enables the operation of opening the target website in the browser and automatically logging into the target webpage, providing access rights for subsequent report downloads, avoiding the labor of repeated manual logins, and improving work efficiency. This automatic login method is stable and reliable, and can be applied to the login of multiple target websites in batches, which is suitable for batch report download tasks.

[0039] Based on the above embodiment, as an optional implementation mode, in S101: opening the target website in the browser and logging in to the target web page in the target website specifically includes: opening the target website in the browser through the WebDriver interface in the Selenium library; entering the user name and password in the login page of the target website and logging in to the target web page.

[0040] In one example, specifically, you first need to import the Selenium library and instantiate a WebDriver object, where you can select a suitable browser driver, such as ChromeDriver, based on actual conditions. This will start the corresponding browser process.

[0041] Then use the get() method of the WebDriver object to enter the URL address of the target website to open the corresponding website login page. For the login box page element, you can use the find_element() method of WebDriver to get the page element objects of the login box and password box, and then use the send_keys() method to automatically enter the username and password in the page element. Finally, call WebDriver's find_element() to get the login button and click() to simulate the click, then the login operation can be completed. If necessary, you can verify whether the login is successful by getting the current page title or URL. Using Selenium's WebDriver interface to realize browser automation control can automate the login process, avoid repeated manual operations, and correctly read and analyze the code of the page after login. Selenium Webdriver provides a rich page element positioning and interaction API, which can be used to realize cross-browser and cross-platform automated testing, and is suitable for the automation of website login in the report batch download task. At the same time, it also makes the program scalable and maintainable.

[0042] After entering the user name and password in the login page of the target website, it also includes determining whether the current page has entered the target webpage of the target website; if the target webpage of the target website has not been entered, the user name and the password are cleared, and the user name and the password are re-entered in the login page. If the user name and the password are re-entered a preset number of times in the login page, an error message is sent to the terminal device of the operator; if the target webpage of the target website is entered, the Cookies information of the current login status is obtained through the Cookie interface of Selenium, and the Cookies information is stored; the target webpage of the target website is accessed through the Get interface of Selenium, and the Cookies information is loaded into the browser.

[0043] In one example, after simulating a login operation using Selenium's WebDriver interface, it is necessary to continue to determine whether the current page has successfully entered the target web page to confirm whether the login is actually effective.

[0044] Specifically, the page source code of the current page is obtained through the page_source method of WebDriver, and then the string matching function is used to determine whether the page source code contains specific HTML elements or text keywords of the target web page. If the page source code does not contain the characteristics of the target web page, it means that the login is unsuccessful and you need to log in again. Here, the entered username and password will be cleared first, and the input box will be cleared through the clear() method of WebDriver; then the previous username and password will be resent; if the login fails after a certain number of cycles (such as 3 times), a login failure prompt needs to be sent, and the error email can be sent to the relevant operation and maintenance personnel by calling the smtplib module that comes with Python.

[0045] If the login is successful, you need to use Selenium's cookie interface to obtain the cookie information containing the login status, which can be achieved through WebDriver's get_cookies() method. At the same time, save the obtained cookies to a local text file. In the subsequent login process, you can directly add this cookie to automatically log in without repeating the login process.

[0046] Finally, use the get() method of WebDriver to access the target web page again, and add the saved cookie information to the browser through add_cookie() to complete the automatic login access to the page.

[0047] In this way, after logging in, you can continue to determine the target page. If you fail, you can repeatedly try to log in again, and save the login status information after success, which can ensure that you can automatically log in to the target website later and avoid repeatedly entering the username and password manually.

[0048] S102, opening multiple target sub-pages in the target web page, and filling in preset search content in the search bar of each target sub-page to perform a search, and obtaining multiple sub-page links.

[0049] In one example, after successfully logging into the target website and entering the target webpage, it is necessary to obtain links to each subpage containing the target report in order to locate the download link later. Since the target report is distributed in different subpages of the target website, it is necessary to open multiple target subpages in the target webpage. The specific method is to access the URL of the subpage in the target webpage through the get() method of WebDriver to open multiple target subpages.

[0050] Then, in each target subpage, you need to get the page element of the search box and enter the preset search keywords related to the report topic in the search box through the send_keys() method. Then find the page element of the search button and click it to submit the search request. The preset keyword search is implemented in each target subpage.

[0051] After the search is completed, the links of multiple sub-page search results, that is, multiple sub-page links, can be extracted by obtaining the page source code of the current page and matching the text in the page source code that conforms to the link format with a regular expression.

[0052] In this way, it is possible to search multiple target subpages using preset keywords and extract subpage links containing search results. This is the basis for determining the report download link later, and it also avoids manual subpage search one by one, improving the efficiency of searching reports. This search automation method can flexibly configure different keywords and apply them in batches to each subpage of the target website to obtain subpage links containing reports.

[0053] S103, obtaining preset keywords and custom extraction rules.

[0054] In one example, in order to accurately locate and extract the download link of the target report from the sub-page link, it is necessary to pre-set keywords related to the report and custom extraction rules for report elements. Keywords need to be determined in advance based on the type and content of the report. For example, product reports can use keywords such as "XX product quarterly report". The extraction rules need to be set according to the actual location of the report in the web page. For example, the report element may be in a div with a class name of "report-block", then the extraction rules can be set to select all div elements with the class containing "report-block".

[0055] For example, define two variables in the code to store preset keywords and custom extraction rules. Keywords can be set in string form, and extraction rules can be set in regular expression form. When the program executes to this step, the values ​​of these two variables are read from the pre-configured file and loaded into the code.

[0056] In this way, the keywords and extraction rules set in advance are obtained by the program and are ready to be used in the subsequent report element extraction. This enables custom configuration of report location extraction rules without hard coding these rules, allowing the program to flexibly adapt to the extraction needs of different websites or different reports, expanding the scope of application of the program. At the same time, it also avoids the inefficient way of manually setting these rules repeatedly, making the report download process smoother and more automated.

[0057] S104, extracting elements corresponding to the target report from each sub-page link according to preset keywords and custom extraction rules, and determining a download link for the target report in each sub-page link according to the elements corresponding to the target report.

[0058] In one example, after obtaining preset keywords and custom extraction rules, it is necessary to locate and extract specific elements of the target report from the sub-page links based on this information to further determine the download link.

[0059] Specifically, it includes: first, traverse each sub-page link and use the page_source attribute of selenium to obtain the page source code. Then, use Python's requests module to search for preset keywords in the page source code and locate the target report element containing the keyword.

[0060] Next, according to the custom extraction rules, further screening is performed among the matched report elements. For example, the HTML document structure of the element is parsed using the BeautifulSoup library, and extraction is performed according to the CSS selector or regular expression in the extraction rules to obtain the report title, release time and other information to constitute the report elements.

[0061] Finally, according to the extracted report element, the download link symbol, such as the href attribute, can be searched in the surrounding HTML documents by matching keywords such as "download", thereby determining the download link corresponding to the report element.

[0062] In this way, using preset keywords and rules, report elements from multiple sub-pages can be automatically extracted in batches, and the download link of each report can be accurately determined without manually analyzing page documents one by one, thereby achieving efficient acquisition of report download links.

[0063] On the basis of the above embodiment, as an optional implementation, in S104: according to preset keywords and custom extraction rules, the elements corresponding to the target report are extracted in each sub-page link, and according to the elements corresponding to the target report, the download link of the target report in each sub-page link is determined, including: obtaining the DOM structure of each sub-page link; according to preset keywords, searching for the first element corresponding to the target report in the DOM structure of each sub-page link; filtering the first element according to the custom extraction rule to obtain the second element; according to the second element, constructing the information structure of the target report; according to the information structure of the target report, determining the download link of the target report in each sub-page link.

[0064] In one example, in order to accurately extract elements of a target report from a subpage and further determine a download link, it is necessary to search and filter the page DOM structure using preset keywords and custom extraction rules.

[0065] The specific implementation method is: first, for each sub-page link, use Selenium's page_source to obtain the entire HTML document of the page, that is, the DOM structure. Then use BeautifulSoup to parse the HTML document to form a tree structure.

[0066] Next, search for nodes containing preset keywords in the document tree. This can be achieved by using the find() method of BeautifulSoup and passing in keywords. The found nodes are the first-class report elements. Subsequently, the first-class elements need to be filtered according to the predetermined CSS selector extraction rules, and only the second-class report elements that meet the extraction rules are retained, so that the target report can be accurately locked. For example, elements with class names containing "report" are retained. For the second-class report elements, BeautifulSoup can be used to extract the text, attributes and other information of the elements to build a report information dictionary, including the report name, date, author and other content. Finally, near the node where the report element is located, match the links related to keywords such as "download", determine whether these links point to pdf files, and determine the download link of the report. Through multiple searches and screenings of the page DOM structure, the precise elements of the report can be automatically and efficiently extracted, and the corresponding download links can be further located to provide accurate link information for subsequent report downloads.

[0067] S105, downloading the target report according to the download link of the target report in each sub-page link, and saving the target report locally.

[0068] In one example, after obtaining the download link corresponding to the target report in each sub-page link, it is necessary to use these links to download the binary content of the report file to the local computer.

[0069] The specific implementation method is: first determine the maximum concurrent number of reasonable download tasks according to the current system resource status and network bandwidth to avoid downloading too many tasks affecting system performance. Then, the download tasks are put into the thread pool in batches according to the maximum concurrent number and executed in sequence. For each report download link, use Python's requests module to obtain the binary data of the file pointed to by the link, and write the data content to the specified folder on the local disk to generate a file corresponding to the file name. The report file can be named according to certain rules, such as including the report name, report date and other information.

[0070] After the download is complete, the integrity of the file content is further verified, such as checking the file size, checksum, etc. Finally, the download status, such as success or failure, is recorded based on the verification result. In this way, this step realizes the efficient and automatic batch download of report files from the server to the local computer based on the report download link obtained in advance, using concurrency control and error checking. This avoids the inefficiency of manual downloading one by one. The locally stored report data can provide convenience for subsequent use. At the same time, the integrity check of the file is also realized to ensure the quality of the downloaded report data.

[0071] Download the target report according to the download link of the target report in each sub-page link, and save the target report locally, including: obtaining system resources and network status; determining the maximum concurrency number of download tasks according to system resources and network dynamics, and downloading the target report according to the maximum concurrency number; when the target report is downloaded, save it locally.

[0072] In one example, the Python psutil module is called to monitor the CPU and memory usage of the current computer, as well as the network upload rate. Based on these system resource states, the maximum number of concurrent download tasks is determined, such as the current system resources can support 20 concurrent downloads.

[0073] Next, use ThreadPoolExecutor of Python's concurrent.futures module to create a thread pool, and set the maximum number of threads to the calculated number of concurrent connections. Then submit all reported download tasks to the thread pool for concurrent downloading.

[0074] During the download process, the system resource usage status is continuously monitored. If it exceeds the predefined threshold, the maximum number of working threads in the thread pool is dynamically adjusted to reduce the concurrency.

[0075] For each report, when it is downloaded, use Python's os and shutil modules to save the report file to the specified local directory, and name the file according to the report name + date. Finally, use the hashlib module to calculate the MD5 checksum of each report file and compare it with the source site checksum to verify the file integrity. This method can fully utilize system resources to increase download speed by controlling the number of concurrent downloads, while also avoiding the problem of excessive system load caused by too many concurrent downloads. After the download is completed, the file integrity is verified, thereby realizing the efficient and stable automatic download and saving of batch reports.

[0076] After the target report is saved locally, it also includes: verifying the integrity of the target report; if the integrity of the target report meets the preset requirements, classifying the target report according to the content, type and business needs of the target report.

[0077] In one example, after a report is downloaded and saved locally, the integrity of the report file needs to be further verified.

[0078] Specifically, you can use Python's hashlib module to generate a HASH checksum value for each report file according to an algorithm such as MD5. And when downloading, you have obtained the MD5 value provided by the source station. Compare the calculated checksum value with the original MD5 value. If they are consistent, it means that the report file is complete, otherwise it means that the download is incomplete or wrong. For those reports that have passed the verification, they also need to be classified and stored according to the content and type of the report for subsequent search and use. You can use Python's jieba module to cut the text content of the report and extract keywords. Determine the category of the report based on the keywords in the report title or text. For example, if it contains "financial report", it is judged as a financial report. At the same time, you can also use the metadata of the report file, such as file name, size, creation time, etc., and combine it with business rules for judgment. For example, product reports are generally named "product + date". Finally, save reports of different categories to their corresponding directory folders.

[0079] In this way, by checking the integrity of the report, incomplete reports caused by download errors can be filtered out, and the reports can be further intelligently classified to achieve automatic archiving of report contents, which not only ensures the quality of the report, but also makes subsequent search and use more convenient and quick.

[0080] The target report is verified for integrity, including: verifying the file name and file size value of the target report; matching the text information in the target report with the report samples stored in the database, and calculating the text similarity; if the file name and file size of the target report pass the verification, and the text similarity is higher than the preset threshold, the target report is judged to have passed the integrity verification.

[0081] In one example, after the download is complete, the target report needs to be verified for integrity to ensure that the obtained report is complete and accurate. The verification method is as follows: First, verify the file name and file size of the target report. The file name needs to be consistent with the preset rules, and the file size needs to be within a reasonable range. This is because the report file itself should follow a fixed naming method, and the file size will directly reflect whether the report content is complete. Next, extract the text information in the report, match it word by word with the report sample stored in the database, and calculate the text similarity between the two. The text similarity algorithm can be implemented using an NLP model or an edit distance algorithm. Since the content of the standard complete report is basically the same as the sample, a high text similarity indicates that the report content is complete. Finally, if the file name and file size verification pass, and the text similarity is higher than the preset threshold (such as 90%), it can be determined that the target report integrity verification has passed.

[0082] This two-fold verification method, combining the attributes and content of the verification report, can ensure the integrity of the report from different dimensions, avoiding incomplete reports due to transmission errors or download interruptions. At the same time, the naming of technical features remains consistent, and the implementation process is discussed in a logical order to make the verification steps clear. Implementing this verification mechanism can effectively filter out incomplete and erroneous reports, ensuring the quality of subsequent analysis and use of reports.

[0083] Based on the above method, the present application also discloses a platform report automatic batch downloading device, such as Figure 2 As shown, Figure 2 It is a structural diagram of a platform report automatic batch downloading device provided in an embodiment of the present application.

[0084] A platform report automatic batch download device comprises: a login module, a search module, an acquisition module, a generation module and a download module; wherein the login module is used to open a target website in a browser and log in to a target webpage in the target website; the search module is used to open multiple target subpages in the target webpage, and fill in preset search content in the search bar of each target subpage to search and obtain multiple subpage links; the acquisition module is used to obtain preset keywords and custom extraction rules; the generation module is used to extract elements corresponding to a target report in each subpage link according to the preset keywords and custom extraction rules, and determine the download link of the target report in each subpage link according to the elements corresponding to the target report; the download module is used to download the target report according to the download link of the target report in each subpage link, and save the target report locally.

[0085] It should be noted that: when the device provided in the above embodiment realizes its function, only the division of the above functional modules is used as an example. In actual application, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0086] See also Figure 3 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 3 As shown, the electronic device 1000 may include: at least one processor 1001 , at least one network interface 1004 , a user interface 1003 , a memory 1005 , and at least one communication bus 1002 .

[0087] The communication bus 1002 is used to realize the connection and communication between these components.

[0088] The user interface 1003 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 1003 may also include a standard wired interface and a wireless interface.

[0089] The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).

[0090] Among them, the processor 1001 may include one or more processing cores. The processor 1001 uses various interfaces and lines to connect various parts in the entire server, and executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 1005, and calling data stored in the memory 1005. Optionally, the processor 1001 can be implemented in at least one hardware form of digital signal processing (Digital, Signal, Processing, DSP), field programmable gate array (Field-Programmable, Gate, Array, FPGA), and programmable logic array (Programmable, Logic, Array, PLA). The processor 1001 can integrate one or a combination of a central processing unit (Central, Processing, Unit, CPU), an image processor (Graphics, Processing, Unit, GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1001, but may be implemented separately through a chip.

[0091] Among them, the memory 1005 may include a random access memory (Random, Access, Memory, RAM) and may also include a read-only memory (Read-Only, Memory). Optionally, the memory 1005 includes a non-transitory, computer-readable, storage, medium. The memory 1005 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1005 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1005 may optionally be at least one storage device located away from the aforementioned processor 1001. As Figure 3 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an application program for a platform report automatic batch downloading method.

[0092] exist Figure 3 In the electronic device 1000 shown, the user interface 1003 is mainly used to provide an input interface for the user and obtain data input by the user; and the processor 1001 can be used to call an application program stored in the memory 1005 for a method for automated batch downloading of platform reports. When executed by one or more processors, the electronic device executes one or more of the methods described in the above embodiments.

[0093] An electronic device readable storage medium stores instructions, which, when executed by one or more processors, enable the electronic device to execute one or more of the methods described in the above embodiments.

[0094] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for the present application.

[0095] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0096] In the several embodiments provided in the present application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0097] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0098] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0099] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: various media that can store program codes, such as USB flash drives, mobile hard drives, magnetic disks or optical disks.

[0100] The above is only an exemplary embodiment of the present disclosure, and the scope of the present disclosure cannot be limited thereto. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the specification and practicing the disclosure here, those skilled in the art will easily think of other embodiments of the present disclosure. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the technical field not recorded in the present disclosure. The description and examples are only regarded as exemplary, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. A method for automatically downloading platform reports in batches, characterized in that: The method comprises: Open the target website in a browser and log in to the target webpage in the target website; Open multiple target sub-pages in the target webpage, and fill in preset search content in the search bar of each target sub-page to perform search, so as to obtain multiple sub-page links; Get preset keywords and custom extraction rules; Extracting elements corresponding to the target report in each of the sub-page links according to the preset keywords and the custom extraction rules, and determining a download link for the target report in each of the sub-page links according to the elements corresponding to the target report; Download the target report according to the download link of the target report in each of the sub-page links, and save the target report locally.

2. The platform report automatic batch downloading method according to claim 1, characterized in that: The step of opening the target website in the browser and logging into the target webpage in the target website includes: Open the target website in the browser through the WebDriver interface in the Selenium library; Enter your username and password on the login page of the target website and log in to the target web page.

3. The platform report automatic batch downloading method according to claim 2, characterized in that: After entering the user name and password in the login page of the target website, the following steps are also included: Determine whether the current page enters the target webpage of the target website; If the target webpage of the target website is not entered, the user name and the password are cleared, and the user name and the password are re-entered on the login page. If the user name and the password are re-entered on the login page a preset number of times, an error message is sent to the terminal device of the operator; If the target webpage of the target website is entered, the Cookies information of the current login status is obtained through the Cookie interface of Selenium, and the Cookies information is stored; The target webpage of the target website is accessed through the Get interface of Selenium, and the Cookies information is loaded into the browser.

4. The platform report automatic batch downloading method according to claim 1, characterized in that: The extracting elements corresponding to the target report in each of the sub-page links according to the preset keywords and the custom extraction rule, and determining the download link of the target report in each of the sub-page links according to the elements corresponding to the target report, includes: Obtain the DOM structure of each sub-page link; According to the preset keyword, searching for the first element corresponding to the target report in the DOM structure of each of the sub-page links; Filter the first element according to the custom extraction rule to obtain a second element; constructing the information structure of the target report according to the second element; According to the information structure of the target report, a download link of the target report in each of the sub-page links is determined.

5. The platform report automatic batch downloading method according to claim 1, characterized in that: The step of downloading the target report according to the download link of the target report in each of the sub-page links and saving the target report locally includes: Get system resources and network status; Determine the maximum concurrent number of download tasks according to the system resources and the network dynamics, and download the target report according to the maximum concurrent number; When the target report is downloaded, the target report is saved locally.

6. The platform according to claim 1 includes an automated batch downloading method, characterized in that: After the target report is saved locally, the method further includes: Verifying the integrity of the target report; If the completeness of the target report meets the preset requirements, the target report will be classified according to the content, type and business needs of the target report.

7. The platform report automatic batch downloading method according to claim 6, characterized in that: The target report is verified for completeness, including: Verifying the file name and file size value of the target report; Matching the text information in the target report with the report samples stored in the database to calculate the text similarity; If the file name and file size of the target report pass the verification, and the text similarity is higher than a preset threshold, it is determined that the integrity verification of the target report passes.

8. A platform report automatic batch downloading device, characterized in that: The device comprises: a login module, a search module, an acquisition module, a generation module and a download module; wherein, The login module is used to open the target website in the browser and log in to the target webpage in the target website; The search module is used to open multiple target sub-pages in the target web page, and fill in the preset search content in the search bar of each target sub-page to perform a search, thereby obtaining multiple sub-page links; The acquisition module is used to acquire preset keywords and custom extraction rules; The generating module is used to extract the elements corresponding to the target report in each of the sub-page links according to the preset keywords and the custom extraction rules, and determine the download link of the target report in each of the sub-page links according to the elements corresponding to the target report; The download module is used to download the target report according to the download link of the target report in each of the sub-page links, and save the target report locally.

9. An electronic device, characterized in that: It includes a processor, a memory user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 7.