CN110516137B - 基于Gecco框架爬取网页数据并与数据库交互的方法 - Google Patents
基于Gecco框架爬取网页数据并与数据库交互的方法 Download PDFInfo
- Publication number
- CN110516137B CN110516137B CN201910814088.3A CN201910814088A CN110516137B CN 110516137 B CN110516137 B CN 110516137B CN 201910814088 A CN201910814088 A CN 201910814088A CN 110516137 B CN110516137 B CN 110516137B
- Authority
- CN
- China
- Prior art keywords
- class
- gecco
- template
- values
- data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/951—Indexing; Web crawling techniques
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/953—Querying, e.g. by the use of web search engines
- G06F16/9535—Search customisation based on user profiles and personalisation
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明涉及网络爬虫技术领域,公开了一种基于Gecco框架爬取网页数据并与数据库交互的方法,用以解决爬取到的数据不能直接而简洁的与相应数据库进行交互的问题。本发明包括:S1、编写一个包含模板类静态属性的工具类;S2、在控制类中通过springboot注解为模板类自动注入值;S3、在控制类中创建Gecco搜索引擎之前,使用步骤S1中创建的工具类对模板类静态属性赋值,其值为步骤S2中所注入值;S4、创建Gecco搜索引擎,开始爬取网页数据;S5、在实现Pipeline<T>的处理类中使用步骤S1的工具类来获取一个模板类的实例;S6、使用步骤S5所创建的实例使通过Gecco爬取的数据与对应数据库实现交互。本发明适用于网页数据爬取。
Description
技术领域
本发明涉及网络爬虫技术领域,特别涉及基于Gecco框架爬取网页数据并与数据库交互的方法。
背景技术
Gecco是一款用java语言开发的轻量化的易用的网络爬虫。Gecco整合了jsoup、httpclient、fastjson、spring、htmlunit、redission等优秀框架。其技术特征在于只需要配置一些jquery风格的选择器就能很快的写出一个爬虫,代码简洁清晰,具有优秀的可扩展性。框架基于开闭原则进行设计,对修改关闭、对扩展开放。Gecco特别适合抓取类似京东商城分类以及分类下的商品信息这一类数据。
但是在同时使用springboot和Gecco爬虫框架时,由于java Bean的注入时间不同,在Gecco框架内部不能够通过springboot的注解来自动注入Template模板类,因此导致爬取到的数据不能直接而简洁的与相应数据库进行交互。
发明内容
本发明要解决的技术问题是:提供一种基于Gecco框架爬取网页数据并与数据库交互的方法,用以解决爬取到的数据不能直接而简洁的与相应数据库进行交互的问题。
为解决上述问题,本发明采用的技术方案是:在springboot框架的控制层中实现自动注入Template模板类,具体步骤如下:
S1、编写一个包含Template模板类静态属性的工具类;
S2、在Controller控制类中通过springboot注解为Template模板类自动注入值;
S3、在Controller控制类中创建Gecco搜索引擎之前,使用步骤S1中创建的工具类对模板类静态属性赋值,其值为步骤S2中所注入值;
S4、创建Gecco搜索引擎,开始爬取网页数据;
S5、在实现Pipeline<T>的处理类中使用步骤S1的工具类来获取一个Template模板类的实例;
S6、在具体实现Pipeline<T>的使用步骤S5所创建的实例使通过Gecco爬取的数据与对应数据库实现交互。
进一步的,为了便于注解,步骤S2可通过springboot的@Autowired注解为模板类自动注入值。
进一步的,为了方便创建,步骤S4可使用Gecco框架自带的方法GeccoEngine.create()来创建搜索引擎。
本发明的有益效果是:本发明通过一个专门用于获取对象实例的工具类来实现Gecco框架内外部之间的联系,以此达到同时使用springboot及Gecco框架并使爬取数据与相应数据库产生交互的目的,具有爬虫代码简洁明了、逻辑清晰、使用范围较广等优点。
附图说明
图1为实施例通过Gecco与springboot实现爬取网页数据并与mongo数据库交互的原理示意图。
具体实施方式
为了在同时使用Gecco和springboot框架时,能够在Gecco框架内部使用通过springboot注解自动注入的Template模板类,并以此来实现将爬取的数据与相应数据库进行交互的目的,本发明提供了一种基于Gecco框架爬取网页数据并与数据库交互的方法,首先,编写了一个专门用于设置及获取相应数据库Template实例的工具类,该工具类中的Template属性是静态的,使用相应的set方法来将Gecco框架外部自动注入的实例赋给它;之后在Gecco内部通过工具类来获取Template的实例,即,使用工具类获取Template模板类对象实例,而不通过springboot的注解注入,这样避免了Gecco和springboot框架间由于java Bean注入时间不同而导致Gecco内部处理爬取数据时的Template模板类实例为空的情况。
本发明的具体实现步骤如下:
(1)需要编写一个包含Template模板类静态属性的工具类;
(2)在Controller控制类中通过springboot注解为Template模板类自动注入值;
(3)在Controller中创建Gecco搜索引擎之前使用步骤(1)中创建的工具类对模板类静态属性赋值,其值为步骤(2)中所注入;
(4)创建Gecco搜索引擎,开始爬取网页数据;
(5)在具体实现Pipeline<T>的处理类中使用步骤(1)的工具类来获取一个Template模板类的实例;
(6)使用步骤(5)所创建的实例使通过Gecco爬取的数据与对应数据库实现交互。
下面结合附图和实施例来详细描述本发明的实例性,实施例具体使用了mongo数据库,如图1所示,具体的工作流程如下:
S1、编写一个名为MongoUtil的用于设置及获取MongoTemplate模板类实例的工具类,该工具类至少存在一个静态的MongoTemplate模板类属性与相应的get及set方法。
S2、在程序的Controller控制类定义一个MongoTemplate属性,并通过springboot的@Autowired注解为该属性注入一个实例。
S3、在Controller控制类的具体方法中使用步骤S1所编写工具类的MongoUtil.setMongoTemplate(mongoTemplate)方法为工具类中的MongoTemplate属性赋值。
S4、使用Gecco框架自带的方法GeccoEngine.create()来创建搜索引擎,并启动搜索,开始爬取指定网站下的数据信息。
S5、定义一个类实现Pipeline<T>,用于处理步骤S4中所爬取到的数据信息。在该类中定义一个类型为MongoTemplate的属性mongo,其值通过步骤S1中MongoUtil工具类的MongoUtil.getMongoTemplate()方法来获取对象实例。
S6通过上一步骤得到的MongoTemplate实例(mongo)即可使所爬取到的数据与指定的mongo数据库产生交互。
Claims (3)
1.基于Gecco框架爬取网页数据并与数据库交互的方法,其特征在于,包括如下步骤:
S1、编写一个包含模板类静态属性的工具类;
S2、在控制类中通过springboot注解为模板类自动注入值;
S3、在控制类中创建Gecco搜索引擎之前,使用步骤S1中创建的工具类对模板类静态属性赋值,其值为步骤S2中所注入值;
S4、创建Gecco搜索引擎,开始爬取网页数据;
S5、在实现Pipeline<T>的处理类中使用步骤S1的工具类来获取一个模板类的实例;
S6、使用步骤S5所创建的实例使通过Gecco爬取的数据与对应数据库实现交互。
2.如权利要求1所述基于Gecco框架爬取网页数据并与数据库交互的方法,其特征在于,步骤S2通过springboot的@Autowired注解为模板类自动注入值。
3.如权利要求1所述基于Gecco框架爬取网页数据并与数据库交互的方法,其特征在于,步骤S4使用Gecco框架自带的方法GeccoEngine.create()来创建搜索引擎。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910814088.3A CN110516137B (zh) | 2019-08-30 | 2019-08-30 | 基于Gecco框架爬取网页数据并与数据库交互的方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910814088.3A CN110516137B (zh) | 2019-08-30 | 2019-08-30 | 基于Gecco框架爬取网页数据并与数据库交互的方法 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110516137A CN110516137A (zh) | 2019-11-29 |
CN110516137B true CN110516137B (zh) | 2022-08-26 |
Family
ID=68629435
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910814088.3A Active CN110516137B (zh) | 2019-08-30 | 2019-08-30 | 基于Gecco框架爬取网页数据并与数据库交互的方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110516137B (zh) |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2017156972A1 (zh) * | 2016-03-17 | 2017-09-21 | 福建联迪商用设备有限公司 | 一种java生成数据库sequence的方法 |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102968465B (zh) * | 2012-11-09 | 2015-07-29 | 同济大学 | 网络信息服务平台及其基于该平台的搜索服务方法 |
CN105843921A (zh) * | 2016-03-25 | 2016-08-10 | 福建星网视易信息系统有限公司 | 一种抓取热歌的方法和装置 |
CN107832197A (zh) * | 2017-11-28 | 2018-03-23 | 江苏方天电力技术有限公司 | 一种业务应用系统的巡检系统和巡检方法 |
-
2019
- 2019-08-30 CN CN201910814088.3A patent/CN110516137B/zh active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2017156972A1 (zh) * | 2016-03-17 | 2017-09-21 | 福建联迪商用设备有限公司 | 一种java生成数据库sequence的方法 |
Non-Patent Citations (2)
Title |
---|
SQL data generation to enhance search-based system testing;Arcuri A 等;《Proceedings of the Genetic and Evolutionary Computation Conference》;20190713;1390-1398 * |
优秀的开源Java爬虫项目;C站训练营学;《https://blog.csdn.net/cpongo3/article/details/89327620?ops_request_misc=&request_id=&biz_id=102&utm_term=gecco%20springboot&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-789327620.nonecase&spm=1018.2226.3001.4187》;20190416;1 * |
Also Published As
Publication number | Publication date |
---|---|
CN110516137A (zh) | 2019-11-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102819492B (zh) | 一种基于Android的关键字驱动自动化测试框架 | |
Schreier | Modeling restful applications | |
Bollati et al. | Applying MDE to the (semi-) automatic development of model transformations | |
Sánchez Ramón et al. | Model-driven reverse engineering of legacy graphical user interfaces | |
US20170177311A1 (en) | Service extraction and application composition | |
CN109597621B (zh) | 封装Dagger的方法、装置、终端设备及存储介质 | |
Herrmannsdörfer et al. | Coupled evolution of software metamodels and models | |
US8656349B2 (en) | Systems and methods for template reverse engineering | |
JP2005196291A (ja) | ユーザインタフェースアプリケーション開発プログラム、および開発装置 | |
Ko et al. | Extending UML meta-model for android application | |
Dixon et al. | Prefab layers and prefab annotations: extensible pixel-based interpretation of graphical interfaces | |
Maté et al. | Tracing conceptual models' evolution in data warehouses by using the model driven architecture | |
Trias et al. | Migrating traditional web applications to CMS-based web applications | |
Reimann et al. | Role-based generic model refactoring | |
CN110516137B (zh) | 基于Gecco框架爬取网页数据并与数据库交互的方法 | |
Von Pilgrim et al. | Model/code co-refactoring: An MDE approach | |
Urbieta et al. | Modeling, deploying, and controlling volatile functionalities in web applications | |
Buchmann et al. | On a-posteriori integration of ecore models and hand-written java code | |
Clerissi et al. | Test driven development of web applications: A lightweight approach | |
Daniel | Live, personal data integration through UI-oriented computing | |
Beaudoux et al. | Specifying and running rich graphical components with loa | |
Martín et al. | AO-WAD: A generalized approach for accessible design within the development of web-based systems | |
Koznov et al. | View to view transformations in domain specific modeling | |
CN114371986A (zh) | 用户界面测试用例更新方法、装置及存储介质 | |
CN111221590A (zh) | 一种获取以chromium为内核的浏览器的URL的方法 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |