Skip to content

Commit ed9b3ac

Browse files
committed
写了个samples
1 parent 01e14fb commit ed9b3ac

File tree

12 files changed

+77
-9
lines changed

12 files changed

+77
-9
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
/.idea
1818
/target
1919
cockroach.iml
20-
*.imi
2120

21+
*.iml

cockroach-annotation/cockroach-annotation.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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" />

cockroach-annotation/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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

cockroach-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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

cockroach-samples/cockroach-samples.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
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" />

cockroach-samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

cockroach-test/cockroach-test.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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" />

0 commit comments

Comments
 (0)