-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
417070c
commit 4c46f73
Showing
3 changed files
with
27 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,12 @@ | |
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 用注解进行配置 | ||
* 登陆oschina演示 | ||
* 启用了cookie后全程请求将会使用同一个cookiestore,也就是能保持延续请求的各种状态,包括需要登录的场景等等,默认不开启。 | ||
* @author 汪浩淼 [[email protected]] | ||
* @since 2015/10/21. | ||
|
@@ -22,26 +24,26 @@ | |
public class UseCookie extends BaseSeimiCrawler { | ||
@Override | ||
public String[] startUrls() { | ||
//用于触发第一个回调函数 | ||
return new String[]{"http://www.oschina.net/"}; | ||
return null; | ||
} | ||
|
||
@Override | ||
public void start(Response response) { | ||
//提交登陆请求 | ||
Request login = Request.build("https://www.oschina.net/action/user/hash_login","afterLogin"); | ||
|
||
public List<Request> startRequests() { | ||
List<Request> requests = new LinkedList<>(); | ||
Request start = Request.build("https://www.oschina.net/action/user/hash_login","start"); | ||
Map<String,String> params = new HashMap<>(); | ||
params.put("email","xx@xx.xx"); | ||
params.put("pwd","xxxxxxxxxxxxxxxxxxxxxxxxxx"); | ||
params.put("email","xxx@xx.com"); | ||
params.put("pwd","xxxxxxxxxxxxxxxxxxx"); | ||
params.put("save_login","1"); | ||
params.put("verifyCode",""); | ||
login.setHttpMethod(HttpMethod.POST); | ||
login.setParams(params); | ||
push(login); | ||
start.setHttpMethod(HttpMethod.POST); | ||
start.setParams(params); | ||
requests.add(start); | ||
return requests; | ||
} | ||
|
||
public void afterLogin(Response response){ | ||
@Override | ||
public void start(Response response) { | ||
logger.info(response.getContent()); | ||
push(Request.build("http://www.oschina.net/home/go?page=blog","minePage")); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters