地质所 沉降监测网建设项目
chenhuan
2024-05-16 0fdd42e318f51f9e3c6581473416af1cca69877f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
package com.javaweb.spider.domain;
 
import com.javaweb.spider.config.SpiderConstants;
import com.javaweb.spider.fast.FastConfigContext;
import com.javaweb.spider.util.FackUserAgentUtil;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.javaweb.common.annotation.Excel;
import com.javaweb.common.core.domain.BaseEntity;
import org.assertj.core.util.Lists;
import us.codecraft.webmagic.pipeline.Pipeline;
import us.codecraft.webmagic.proxy.Proxy;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 爬虫配置对象 spider_config
 * 
 * @author wujiyue
 * @date 2019-11-11
 */
@Data
public class SpiderConfig2 extends BaseEntity
{
//    private static final long serialVersionUID = 1L;
//
//    /** 爬虫配置ID */
//    private Long id;
//    /** 爬虫编码 */
//    @Excel(name = "爬虫编码")
//    private String spiderCode;
//    /** 爬虫名称 */
//    @Excel(name = "爬虫名称")
//    private String spiderName;
//
//    /** 入口地址 */
//    private String entryUrls;
//
//    /** 目标URL正则 */
//    private String targetRegex;
//
//    /** 存储的表名 */
//    @Excel(name = "存储的表名")
//    private String tableName;
//
//    public String getSpiderCode() {
//        return spiderCode;
//    }
//    public void setSpiderCode(String spiderCode) {
//        this.spiderCode = spiderCode;
//    }
//    public String getSpiderName() {
//        return spiderName;
//    }
//    public void setSpiderName(String spiderName) {
//        this.spiderName = spiderName;
//    }
//    public String getTableName() {
//        return tableName;
//    }
//    public void setTableName(String tableName) {
//        this.tableName = tableName;
//    }
//    public List<Cookie> getCookies() {
//        return cookies;
//    }
//    public void setCookies(List<Cookie> cookies) {
//        this.cookies = cookies;
//    }
//    public Map<String, String> getHeaders() {
//        return headers;
//    }
//    public void setHeaders(Map<String, String> headers) {
//        this.headers = headers;
//    }
//    public String getUa() {
//        return ua;
//    }
//    public void setUa(String ua) {
//        this.ua = ua;
//    }
//    public List<Pipeline> getPipelineList() {
//        return pipelineList;
//    }
//    public void setPipelineList(List<Pipeline> pipelineList) {
//        this.pipelineList = pipelineList;
//    }
//    public List<Proxy> getProxyList() {
//        return proxyList;
//    }
//    public void setProxyList(List<Proxy> proxyList) {
//        this.proxyList = proxyList;
//    }
//    public static long getSerialversionuid() {
//        return serialVersionUID;
//    }
//    public String getEntryUrls() {
//        return entryUrls;
//    }
//    public String getTargetRegex() {
//        return targetRegex;
//    }
//    public String getDomain() {
//        return domain;
//    }
//    public String getCharset() {
//        return charset;
//    }
//    public Long getSleepTime() {
//        return sleepTime;
//    }
//    public Integer getRetryTimes() {
//        return retryTimes;
//    }
//    public Long getThreadCount() {
//        return threadCount;
//    }
//    public Integer getUseProxy() {
//        return useProxy;
//    }
//    public Integer getShowLog() {
//        return showLog;
//    }
//    public String getExitWay() {
//        return exitWay;
//    }
//    public int getCount() {
//        return count;
//    }
//    public Integer getCascade() {
//        return cascade;
//    }
//    public List<String> getEntryUrlsList() {
//        return entryUrlsList;
//    }
//    public List<SpiderField> getFieldsList() {
//        return fieldsList;
//    }
//    public boolean isConvertImg() {
//        return convertImg;
//    }
//    public String getUserId() {
//        return userId;
//    }
//    /** 网站根域名 */
//    @Excel(name = "网站根域名")
//    private String domain;
//
//    /** 字符集 */
//    @Excel(name = "字符集")
//    private String charset = "utf8";
//
//    /** 睡眠时间(ms) */
//    @Excel(name = "睡眠时间(ms)")
//    private Long sleepTime= 1000L;
//
//    /** 重试次数 */
//    @Excel(name = "重试次数")
//    private Integer retryTimes = 2;
//
//    /** 线程数量 */
//    @Excel(name = "线程数量")
//    private Long threadCount = 1L;
//
//    /** 使用代理 */
//    @Excel(name = "使用代理")
//    private Integer useProxy =0 ;
//    @Excel(name = "打印日志")
//    private Integer showLog=1;
//    /**
//     * 退出方式{DURATION:爬虫持续的时间,URL_COUNT:抓取到的url数量}
//     */
//    private String exitWay = ExitWayEnum.URL_COUNT.toString();
//    /**
//     * 对应退出方式,当exitWay = URL_COUNT时,该值表示url数量,当exitWay = DURATION时,该值表示爬虫持续的时间
//     */
//    private int count;
//
//    private Integer cascade=0;//默认0表示支持入口URL发现目标URL,而不从目标URL级联收集URL
//
//    private List<Cookie> cookies = new ArrayList<>();
//    private Map<String, String> headers = new HashMap<>();
//    private String ua = FackUserAgentUtil.getUserAgent();
//    /** 入口地址集合 */
//    private List<String> entryUrlsList= Lists.newArrayList();
//
//    private List<SpiderField> fieldsList=Lists.newArrayList();
//
//    private List<Pipeline> pipelineList=Lists.newArrayList();
//    /**
//     * 是否转存图片,当选择true时会自动过滤原文中的img链接,调用端可选择将图片下载后替换掉原来的图片
//     */
//    private boolean convertImg = false;
//    private List<Proxy> proxyList = new ArrayList<>();
//
//    private String userId;//扩展字段,无数据库字段对应。对应于爬取某个人的博客的作者uid
//
//    public static SpiderConfig2 create(){
//        return new SpiderConfig2();
//    }
//    public void setExitWay(String exitWay) {
//        this.exitWay = exitWay;
//    }
//
//    public SpiderConfig2 setExitWay(ExitWayEnum exitWay) {
//        this.exitWay = exitWay.toString();
//        this.count = exitWay.getDefaultCount();
//        return this;
//    }
//    public SpiderConfig2 setConvertImg(boolean convertImg) {
//        this.convertImg = convertImg;
//        return this;
//    }
//
//    public SpiderConfig2 setCount(int count) {
//        this.count = count;
//        return this;
//    }
//
//    public SpiderConfig2 setHeader(String key, String value) {
//        Map<String, String> headers = this.getHeaders();
//        headers.put(key, value);
//        return this;
//    }
//
//    public SpiderConfig2 setHeader(String headersStr) {
//        if (StringUtils.isNotEmpty(headersStr)) {
//            String[] headerArr = headersStr.split("\r\n");
//            for (String s : headerArr) {
//                String[] header = s.split("=");
//                setHeader(header[0], header[1]);
//            }
//        }
//        return this;
//    }
//
//    public SpiderConfig2 setCookie(String domain, String key, String value) {
//        List<Cookie> cookies = this.getCookies();
//        cookies.add(new Cookie(domain, key, value));
//        return this;
//    }
//
//    public SpiderConfig2 setCookie(String cookiesStr) {
//        if (StringUtils.isNotEmpty(cookiesStr)) {
//            List<Cookie> cookies = this.getCookies();
//            String[] cookieArr = cookiesStr.split(";");
//            for (String aCookieArr : cookieArr) {
//                String[] cookieNode = aCookieArr.split("=");
//                if (cookieNode.length <= 1) {
//                    continue;
//                }
//                cookies.add(new Cookie(cookieNode[0].trim(), cookieNode[1].trim()));
//            }
//        }
//        return this;
//    }
//
//
//    private void addProxy(Proxy proxy) {
//        if (this.useProxy == 0 || null == this.useProxy || null == proxy) {
//            return;
//        }
//        proxyList.add(proxy);
//    }
//
//    public SpiderConfig2 setProxy(String proxyStr) {
//        if (this.useProxy  == 0 || null == this.useProxy || proxyStr == null) {
//            return this;
//        }
//        String[] proxyArr = proxyStr.split(",");
//        for (String s : proxyArr) {
//            String[] proxy = s.split(":");
//            if (proxy.length == 2) {
//                this.addProxy(new Proxy(proxy[0], Integer.parseInt(proxy[1])));
//            } else if (proxy.length == 4) {
//                this.addProxy(new Proxy(proxy[0], Integer.parseInt(proxy[1]), proxy[2], proxy[3]));
//            }
//        }
//        return this;
//    }
//    public SpiderConfig2 setEntryUrls(String entryUrls) {
//        this.entryUrls = entryUrls;
//        if(StringUtils.isNotEmpty(entryUrls)){
//            String[] arr=entryUrls.split(",");
//            for(String s:arr){
//                if(StringUtils.isNotEmpty(s)){
//                    entryUrlsList.add(s);
//                }
//            }
//        }
//        return this;
//    }
//    public SpiderConfig2 addEntryUrl(String entryUrl) {
//        this.entryUrlsList.add(entryUrl);
//        return this;
//    }
//    public void setEntryUrlsList(List<String> entryUrlsList) {
//        this.entryUrlsList = entryUrlsList;
//    }
//
//    public SpiderConfig2 setFieldsList(List<SpiderField> fieldsList) {
//        if(CollectionUtils.isEmpty(fieldsList)){
//            return this;
//        }
//        this.fieldsList.addAll(fieldsList);
//        return this;
//    }
//
//    /**
//     * 增加一个爬取字段
//     * @param field
//     * @return
//     */
//    public SpiderConfig2 addField(SpiderField field) {
//        if(field==null||StringUtils.isEmpty(field.getField())){
//            return this;
//        }
//        this.fieldsList.add(field);
//        return this;
//    }
//    /**
//     * 增加一个数据管道
//     * @param pipeline
//     * @return
//     */
//    public SpiderConfig2 addPipeline(Pipeline pipeline) {
//        if(pipeline==null){
//            return this;
//        }
//        this.pipelineList.add(pipeline);
//        return this;
//    }
//
//    /**
//     * 增加一个xpath提取规则字段
//     * @param field
//     * @param fieldName
//     * @param xpath
//     * @return
//     */
//    public SpiderConfig2 addField(String field,String fieldName,String xpath) {
//        SpiderField spiderField=new SpiderField();
//        spiderField.setField(field);
//        spiderField.setFieldName(fieldName);
//        spiderField.setExtractType(SpiderConstants.FIELD_EXTRACT_TYPE_XPATH);
//        spiderField.setExtractBy(xpath);
//        this.fieldsList.add(spiderField);
//        return this;
//    }
//
//    public SpiderConfig2 setTargetRegex(String targetRegex) {
//        this.targetRegex = targetRegex;
//        return this;
//    }
//
//    public SpiderConfig2 setThreadCount(Long threadCount) {
//        this.threadCount = threadCount;
//        return this;
//    }
//
//    public SpiderConfig2 setShowLog(Integer showLog) {
//        this.showLog = showLog;
//        return this;
//    }
//
//    public SpiderConfig2 setSleepTime(Long sleepTime) {
//        this.sleepTime = sleepTime;
//        return this;
//    }
//
//    public SpiderConfig2 setDomain(String domain) {
//        this.domain = domain;
//        return this;
//    }
//
//    public SpiderConfig2 setCharset(String charset) {
//        this.charset = charset;
//        return this;
//    }
//
//    public SpiderConfig2 setRetryTimes(Integer retryTimes) {
//        this.retryTimes = retryTimes;
//        return this;
//    }
//
//    public SpiderConfig2 setUseProxy(Integer useProxy) {
//        this.useProxy = useProxy;
//        return this;
//    }
//
//    public SpiderConfig2 setCascade(Integer cascade) {
//        this.cascade = cascade;
//        return this;
//    }
//
//    /**
//     * 爬取某个人博客时候博主的用户id
//     * @param userId
//     * @return
//     */
//    public SpiderConfig2 setUserId(String userId) {
//        this.userId = userId;
//        return FastConfigContext.replaceConfigUid(this);
//    }
//    public Long getId() {
//        return id;
//    }
//    public void setId(Long id) {
//        this.id = id;
//    }
//    
    
}