File tree Expand file tree Collapse file tree 12 files changed +77
-9
lines changed
java/com/zhangyingwei/cockroach/samples/oschina Expand file tree Collapse file tree 12 files changed +77
-9
lines changed Original file line number Diff line number Diff line change 1717/.idea
1818/target
1919cockroach.iml
20- * .imi
2120
21+ * .iml
Original file line number Diff line number Diff line change 1010 </content >
1111 <orderEntry type =" inheritedJdk" />
1212 <orderEntry type =" sourceFolder" forTests =" false" />
13- <orderEntry type =" module " module- name =" cockroach-core" />
13+ <orderEntry type =" library " name =" Maven: com.github.zhangyingwei: cockroach-core:1.0.5.03-Beta " level = " project " />
1414 <orderEntry type =" library" name =" Maven: com.squareup.okhttp3:okhttp:3.8.1" level =" project" />
1515 <orderEntry type =" library" name =" Maven: com.squareup.okio:okio:1.13.0" level =" project" />
1616 <orderEntry type =" library" name =" Maven: net.sf.json-lib:json-lib:jdk15:2.4" level =" project" />
Original file line number Diff line number Diff line change 55 <parent >
66 <artifactId >cockroach</artifactId >
77 <groupId >com.github.zhangyingwei</groupId >
8- <version >1.0.5.03 -Beta</version >
8+ <version >1.0.5.04 -Beta</version >
99 </parent >
1010 <modelVersion >4.0.0</modelVersion >
1111
Original file line number Diff line number Diff line change 55 <parent >
66 <artifactId >cockroach</artifactId >
77 <groupId >com.github.zhangyingwei</groupId >
8- <version >1.0.5.03 -Beta</version >
8+ <version >1.0.5.04 -Beta</version >
99 </parent >
1010 <modelVersion >4.0.0</modelVersion >
1111
Original file line number Diff line number Diff line change 1111 </content >
1212 <orderEntry type =" inheritedJdk" />
1313 <orderEntry type =" sourceFolder" forTests =" false" />
14- <orderEntry type =" module " module- name =" cockroach-core" />
14+ <orderEntry type =" library " name =" Maven: com.github.zhangyingwei: cockroach-core:1.0.5.03-Beta " level = " project " />
1515 <orderEntry type =" library" name =" Maven: com.squareup.okhttp3:okhttp:3.8.1" level =" project" />
1616 <orderEntry type =" library" name =" Maven: com.squareup.okio:okio:1.13.0" level =" project" />
1717 <orderEntry type =" library" name =" Maven: net.sf.json-lib:json-lib:jdk15:2.4" level =" project" />
Original file line number Diff line number Diff line change 55 <parent >
66 <artifactId >cockroach</artifactId >
77 <groupId >com.github.zhangyingwei</groupId >
8- <version >1.0.5.03 -Beta</version >
8+ <version >1.0.5.04 -Beta</version >
99 </parent >
1010 <modelVersion >4.0.0</modelVersion >
1111
Original file line number Diff line number Diff line change 1+ package com .zhangyingwei .cockroach .samples .oschina ;
2+
3+ import com .zhangyingwei .cockroach .CockroachApplication ;
4+ import com .zhangyingwei .cockroach .annotation .AppName ;
5+ import com .zhangyingwei .cockroach .annotation .EnableAutoConfiguration ;
6+ import com .zhangyingwei .cockroach .annotation .Store ;
7+ import com .zhangyingwei .cockroach .annotation .ThreadConfig ;
8+ import com .zhangyingwei .cockroach .executer .task .Task ;
9+ import com .zhangyingwei .cockroach .queue .CockroachQueue ;
10+ import com .zhangyingwei .cockroach .queue .TaskQueue ;
11+ import com .zhangyingwei .cockroach .samples .oschina .store .OsChinaStore ;
12+
13+ /**
14+ * Created by zhangyw on 2018/2/26.
15+ */
16+
17+ @ EnableAutoConfiguration
18+ @ AppName ("开源中国博客爬虫" )
19+ @ ThreadConfig (num = 10 ,sleep = 500 )
20+ @ Store (OsChinaStore .class )
21+ public class OschinaApplicatoin {
22+ public static void main (String [] args ) throws Exception {
23+ CockroachQueue queue = TaskQueue .of ();
24+ for (int i = 1 ; i <= 10 ; i ++) {
25+ queue .push (new Task ("https://www.oschina.net/action/ajax/get_more_recommend_blog?classification=0&p=" +i ,"oschina.blog" ).retry (5 ));
26+ }
27+ CockroachApplication .run (OschinaApplicatoin .class , queue );
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ package com .zhangyingwei .cockroach .samples .oschina .store ;
2+
3+ import com .zhangyingwei .cockroach .executer .response .TaskResponse ;
4+ import com .zhangyingwei .cockroach .executer .task .Task ;
5+ import com .zhangyingwei .cockroach .store .IStore ;
6+ import org .jsoup .select .Elements ;
7+
8+ import java .util .List ;
9+
10+ /**
11+ * Created by zhangyw on 2018/2/26.
12+ */
13+ public class OsChinaStore implements IStore {
14+ @ Override
15+ public void store (TaskResponse response ) throws Exception {
16+ if (response .isGroup ("oschina.blog" )) {
17+ response .select (".item" ).forEach (item -> {
18+ String href = item .select (".blog-title-link" ).attr ("href" );
19+ try {
20+ response .getQueue ().push (new Task (href ,"oschina.blog.item" ));
21+ } catch (Exception e ) {
22+ e .printStackTrace ();
23+ }
24+ });
25+ } else if (response .isGroup ("oschina.blog.item" )) {
26+ Elements content = response .select (".blog-content" );
27+ String title = content .select (".title" ).text ().replace ("原 荐 " ,"" );
28+ String autor = content .select (".name" ).text ();
29+ System .out .println (String .format ("文章标题: %s 作者: %s" ,title ,autor ));
30+ }
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ # Root logger option
2+ log4j.rootLogger =INFO,stdout
3+ # Direct log messages to stdout
4+ log4j.appender.stdout =org.apache.log4j.ConsoleAppender
5+ log4j.appender.stdout.Target =System.out
6+ log4j.appender.stdout.layout =org.apache.log4j.PatternLayout
7+ log4j.appender.stdout.layout.ConversionPattern =[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c{1}:%L - %m%n
Original file line number Diff line number Diff line change 1010 </content >
1111 <orderEntry type =" inheritedJdk" />
1212 <orderEntry type =" sourceFolder" forTests =" false" />
13- <orderEntry type =" module " module- name =" cockroach-core" />
13+ <orderEntry type =" library " name =" Maven: com.github.zhangyingwei: cockroach-core:1.0.5.03-Beta " level = " project " />
1414 <orderEntry type =" library" name =" Maven: com.squareup.okhttp3:okhttp:3.8.1" level =" project" />
1515 <orderEntry type =" library" name =" Maven: com.squareup.okio:okio:1.13.0" level =" project" />
1616 <orderEntry type =" library" name =" Maven: net.sf.json-lib:json-lib:jdk15:2.4" level =" project" />
You can’t perform that action at this time.
0 commit comments