zoukankan      html  css  js  c++  java
  • j网络爬虫之WebMagic

    WebMagic官网:http://webmagic.io/

    注意:

    1、在自定义PageProcessor中使用System.out.println(“str”),Spider.create(new myPageProcessor()).start()爬虫启动后,console并不会输出

    spider.addPipeline(new ConsolePipeline())//在控制台上输出
    

     

    webMagic之post请求 

    请求参数为form

    	@Test
    	public void webMagicTest1() {
    		String str = "一人之下";
    		Map<String,Object> map  = new HashMap<String,Object>();
    		map.put("keyword", str);
    		Request request = new Request("https://www.80s.tw/search");
    		request.setMethod(HttpConstant.Method.POST);
    		request.setRequestBody(HttpRequestBody.form(map, "utf-8"));
    		Spider.create(new webMagic1())
    				.addRequest(request)
    				.addPipeline(new JsonFilePipeline("D:\webmagic\"))
    				.addPipeline(new ConsolePipeline())
    				.run();
    	}
    

      请求参数为json

    	@Test
    	public void webMagicTest1() {
    		String name = "一人之下";
    		JSONObject json = new JSONObject();
    		json.put("keyword", name);
    		Request request = new Request("https://www.80s.tw/search");
    		request.setMethod(HttpConstant.Method.POST);
    		request.setRequestBody(HttpRequestBody.json(json.toString(), "utf-8"));
    		Spider.create(new webMagic1())
    				.addRequest(request)
    				.addPipeline(new JsonFilePipeline("D:\webmagic\"))
    				.addPipeline(new ConsolePipeline())
    				.run();
    	}
    

      

  • 相关阅读:
    3.28
    03.21
    03.16
    03.15
    03.14小记
    [LC] 96. Unique Binary Search Trees
    [LC] 298. Binary Tree Longest Consecutive Sequence
    [LC] 102. Binary Tree Level Order Traversal
    [LC] 107. Binary Tree Level Order Traversal II
    [LC] 513. Find Bottom Left Tree Value
  • 原文地址:https://www.cnblogs.com/zhumengke/p/8868257.html
Copyright © 2011-2022 走看看