Skip to content

Commit

Permalink
add infinite function to infinite down once html
Browse files Browse the repository at this point in the history
  • Loading branch information
nonacosa committed Oct 18, 2017
1 parent f225b6a commit 361ee72
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
4 changes: 2 additions & 2 deletions webBee-core/src/main/java/org/bee/webBee/Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public static Bee create(PageProcessor pageProcessor) {
public void run() {
BeeExecutorPool beeThreadPool = new BeeExecutorPool(threadNum);
requestProcessor();
while (request != null ) {
if (COUNT >= 1 ) {
while (request != null || setting.getInfinite()) {
if (COUNT >= 1 || setting.getInfinite()) {
if (!requestNextProcessor()) break;
//// if(!checkResultData()) break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PageAnnotationProcess implements PageProcessor

@Override
public void process(Page page) throws IOException {

}

@Override
Expand Down
22 changes: 22 additions & 0 deletions webBee-core/src/main/java/org/bee/webBee/processor/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Setting {

private Map<String, String> headers = new LinkedHashMap<String, String>();//todo Collections.synchronizedMap?

private boolean infinite = false;

/**
* 个性化配置类入口返回配置对象,省去了new Setting()的步骤
*
Expand All @@ -52,6 +54,17 @@ public static Setting create() {
return new Setting();
}


/**
* 设置是否暴利无限下载
*
* @return
*/
public Setting setInfinite(boolean infinite) {
this.infinite = infinite;
return this;
}

/**
* 设置一个作用域
*
Expand Down Expand Up @@ -139,6 +152,15 @@ public String getUserName() {
return userName;
}

/**
* 获取已经设置的账户
*
* @return
*/
public boolean getInfinite() {
return infinite;
}

/**
* 获取已经设置的密码
*
Expand Down
64 changes: 64 additions & 0 deletions webBee-core/src/test/java/example/CountJueJin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package example; /**
* Created by zhuang on 2017/3/23.
*/



import org.bee.webBee.Bee;
import org.bee.webBee.linker.Page;
import org.bee.webBee.processor.PageProcessor;
import org.bee.webBee.processor.Setting;


/**
* 类似servlet 实现HttpServlet doGet doPost 方法的方式定义爬虫
* data 2017-03-23 01:19
* E-mail [email protected]
* @author sis.nonacosa
*/

public class CountJueJin implements PageProcessor {

private Setting setting;

@Override
public void process(Page page) {
//todo page.getJson/html/string().$('textarea.content').as('content').bulid().$('#img').as('img')
//todo 期望结果: {content:[],img:[]} 一条{}多条[] 的json格式
//todo page.nextUrl('span>ss>s')
//todo 直接获取api接口

String json = page.getHtml().$("a").as("title").toJSONString();
//
System.out.println(json);


}

@Override
public Setting getSetting() {
System.out.println("This is example.MainDemoByUrl's setting function ...");
setting = Setting.create().setStartUrl("https://juejin.im/user/5823d1a3a22b9d0067fde1f7");
//添加cookie,模拟登陆 也可以选择setting.addCookie(key,value)添加cookie;
setting = setting.addHeader("Set-Cookie","QINGCLOUDELB=6d0ab4ef124aa52bf550d3255fa396ebab7e48fb3972913efd95d72fe838c4fb|WebLd|WebLd; path=/");
setting = setting.addHeader("Server","nginx/1.10.2");
setting = setting.setDomain("juejin.im");
setting = setting.setHttpMethod("GET");
setting = setting.setInfinite(true);
return setting;
}



public static void main(String[] args) {
for(int i=0;i<100;i++) {
try {
Thread.sleep(5000L);
Bee.create(new CountJueJin()).run();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}
}

0 comments on commit 361ee72

Please sign in to comment.