当前位置: 首页>>代码示例>>Java>>正文


Java SpiderThreadLocal类代码示例

本文整理汇总了Java中com.geccocrawler.gecco.spider.SpiderThreadLocal的典型用法代码示例。如果您正苦于以下问题:Java SpiderThreadLocal类的具体用法?Java SpiderThreadLocal怎么用?Java SpiderThreadLocal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SpiderThreadLocal类属于com.geccocrawler.gecco.spider包,在下文中一共展示了SpiderThreadLocal类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: log

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static void log(String message, Class<? extends SpiderBean> spiderBeanClass, Throwable cause) {
	boolean debug = SpiderThreadLocal.get().getEngine().isDebug();
	log.error(spiderBeanClass.getName() + " render error : " + message);
	if(debug && cause != null) {
		log.error(message, cause);
	}
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:8,代码来源:RenderException.java

示例2: log

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static void log(Field field, String message, Throwable cause) {
	boolean debug = SpiderThreadLocal.get().getEngine().isDebug();
	log.error(field.getName() + " render error : " + message);
	if(debug && cause != null) {
		log.error(message, cause);
	}
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:8,代码来源:FieldRenderException.java

示例3:

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public Elements $(String selector) {
	Elements elements = document.select(selector);
	if (SpiderThreadLocal.get().getEngine().isDebug()) {
		if (!selector.equalsIgnoreCase("script")) {
			// log.debug("["+selector+"]--->["+elements+"]");
			System.out.println("[" + selector + "]--->[" + elements + "]");
		}
	}
	return elements;
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:11,代码来源:HtmlParser.java

示例4: get

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static Proxys get() {
	Spider spider = SpiderThreadLocal.get();
	if(spider == null) {
		return null;
	}
	return spider.getEngine().getProxysLoader();
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:8,代码来源:ProxysContext.java

示例5: isEnableProxy

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static boolean isEnableProxy() {
	Spider spider = SpiderThreadLocal.get();
	if(spider == null) {
		return false;
	}
	return spider.getEngine().isProxy();
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:8,代码来源:ProxysContext.java

示例6: download

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public HttpResponse download(HttpRequest request, int timeout) throws DownloadException {
	try {
		URL url = new URL(request.getUrl());
		WebRequest webRequest = new WebRequest(url);
		webRequest.setHttpMethod(HttpMethod.GET);
		if(request instanceof HttpPostRequest) {//post
			HttpPostRequest post = (HttpPostRequest)request;
			webRequest.setHttpMethod(HttpMethod.POST);
			List<NameValuePair> requestParameters = new ArrayList<NameValuePair>();
			for(Map.Entry<String, Object> entry : post.getFields().entrySet()) {
				NameValuePair nvp = new NameValuePair(entry.getKey(), entry.getValue().toString());
				requestParameters.add(nvp);
			}
			webRequest.setRequestParameters(requestParameters);	
		}
		//header
		boolean isMobile = SpiderThreadLocal.get().getEngine().isMobile();
		webRequest.setAdditionalHeader("User-Agent", UserAgent.getUserAgent(isMobile));
		webRequest.setAdditionalHeaders(request.getHeaders());
		//proxy
		HttpHost proxy = Proxys.getProxy();
		if(proxy != null) {
			webRequest.setProxyHost(proxy.getHostName());
			webRequest.setProxyPort(proxy.getPort());
		}
		//timeout
		this.webClient.getOptions().setTimeout(timeout);
		//request,response
		webClient.getPage(webRequest);
		HtmlPage page = webClient.getPage(request.getUrl());
		HttpResponse resp = new HttpResponse();
		WebResponse webResponse = page.getWebResponse();
		int status = webResponse.getStatusCode();
		resp.setStatus(status);
		if(status == 302 || status == 301) {
			String redirectUrl = webResponse.getResponseHeaderValue("Location");
			resp.setContent(UrlUtils.relative2Absolute(request.getUrl(), redirectUrl));
		} else if(status == 200) {
			String content = page.asXml();
			resp.setContent(content);
			resp.setRaw(webResponse.getContentAsStream());
			String contentType = webResponse.getContentType();
			resp.setContentType(contentType);
			String charset = getCharset(request.getCharset(), contentType);
			resp.setCharset(charset);
		} else {
			throw new DownloadException("ERROR : " + status);
		}
		return resp;
	} catch(Exception ex) {
		throw new DownloadException(ex);
	}
}
 
开发者ID:xtuhcy,项目名称:gecco-htmlunit,代码行数:54,代码来源:HtmlUnitDownloder.java

示例7: getRender

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static Render getRender(RenderType type){
	return SpiderThreadLocal.get().getEngine().getSpiderBeanFactory().getRenderFactory().getRender(type);
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:4,代码来源:RenderContext.java

示例8: getRet

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static Object getRet(){
    return SpiderThreadLocal.get().getEngine().getRet();
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:4,代码来源:EngineRetUtil.java

示例9: setRet

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static void setRet(Object o){
    SpiderThreadLocal.get().getEngine().setRet(o);
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:4,代码来源:EngineRetUtil.java

示例10: HttpClientDownloader

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public HttpClientDownloader() {
	
	cookieContext = HttpClientContext.create();
	cookieContext.setCookieStore(new BasicCookieStore());
	
	Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
	try {
		//构造一个信任所有ssl证书的httpclient
		SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
			@Override
			public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
				return true;
			}
		}).build();
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
		socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
		           .register("http", PlainConnectionSocketFactory.getSocketFactory())  
		           .register("https", sslsf)  
		           .build();
	} catch(Exception ex) {
		socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
           .register("http", PlainConnectionSocketFactory.getSocketFactory())
           .register("https", SSLConnectionSocketFactory.getSocketFactory())
           .build();
	}
	RequestConfig clientConfig = RequestConfig.custom().setRedirectsEnabled(false).build();
	PoolingHttpClientConnectionManager syncConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
	syncConnectionManager.setMaxTotal(1000);
	syncConnectionManager.setDefaultMaxPerRoute(50);
	httpClient = HttpClientBuilder.create()
			.setDefaultRequestConfig(clientConfig)
			.setConnectionManager(syncConnectionManager)
			.setRetryHandler(new HttpRequestRetryHandler() {
				@Override
				public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
					int retryCount = SpiderThreadLocal.get().getEngine().getRetry();
					boolean retry = (executionCount <= retryCount);
					if(log.isDebugEnabled() && retry) {
						log.debug("retry : " + executionCount);
					}
					return retry;
				}
			}).build();
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:45,代码来源:HttpClientDownloader.java

示例11: download

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static HttpResponse download(HttpRequest request) throws DownloadException {
	SpiderBeanContext context = SpiderThreadLocal.get().getSpiderBeanContext();
	return context.getDownloader().download(request, context.getTimeout());
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:5,代码来源:DownloaderContext.java

示例12: defaultDownload

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static HttpResponse defaultDownload(HttpRequest request) throws DownloadException {
	SpiderBeanContext context = SpiderThreadLocal.get().getSpiderBeanContext();
	Downloader downloader = SpiderThreadLocal.get().getEngine().getSpiderBeanFactory().getDownloaderFactory().defaultDownloader();
	return downloader.download(request, context.getTimeout());
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:6,代码来源:DownloaderContext.java

示例13: into

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static void into(HttpRequest request) {
	SpiderThreadLocal.get().getSpiderScheduler().into(request);
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:4,代码来源:DeriveSchedulerContext.java

示例14: into

import com.geccocrawler.gecco.spider.SpiderThreadLocal; //导入依赖的package包/类
public static void into(HttpRequest request) {
	SpiderThreadLocal.get().getEngine().getScheduler().into(request);
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:4,代码来源:StartSchedulerContext.java


注:本文中的com.geccocrawler.gecco.spider.SpiderThreadLocal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。