首页 文章 精选 留言 我的

精选列表

搜索[Solon框架],共10000篇文章
优秀的个人博客,低调大师

Apache Juneau 8.1.0 发布,REST 微服务框架

Apache Juneau 8.1.0 发布了。Juneau 是一个多功能的 Java 生态系统,其功能包括 POJO 编组、用于序列化和解析 HTML5、Swagger 与 ATOM 等语言的 DTO、配置 API、通用 REST 服务器/客户端 API、Spring beans 转换部署、微服务 API 与REST 微服务 API 等。 此版本更新内容: 用于在 REST 类/方法上配置序列化程序和解析器的新注解。 几个新的默认 POJO 交换和对 Java 8 时间类的支持。 配置文件导入。 REST 资源路径中的路径变量。 基于角色的 REST 保护。 改进 REST 日志 API。 新的 MockRest API,用于简化 REST 接口的单元测试。 详情查看邮件公告。

优秀的个人博客,低调大师

Apache Flink 1.9.0 发布,开源流处理框架

Apache Flink 1.9.0 已经发布,Apache Flink 项目的目标是开发一个流处理系统,以统一和支持多种形式的实时和离线数据处理应用程序以及事件驱动的应用程序。 此版本包括批处理作业的批处理式恢复,以及新的基于闪烁的表 API 和 SQL 查询引擎的预览,还有状态处理器 API 的可用性,它是最常见的请求特性之一,允许用户使用 Flink DataSet 作业读写保存点。最后,包括一个重新设计的 WebUI 和 Flink 新的 Python Table API 的预览以及它与 Apache Hive 生态系统的集成。 TableAPI & SQL 将 Table 模块进行拆分(FLIP-32,FLIP 即 Flink Improvement Proposals,专门记录一些对Flink 做较大修改的提议),对 Java 和 Scala 的 API 进行依赖梳理,并且提出了 Planner 接口以支持多种不同的 Planner 实现。Planner 将负责具体的优化和将 Table 作业翻译成执行图的工作,我们可以将原来的实现全部挪至 Flink Planner 中,然后把对接新架构的代码放在 Blink Planner 里。 不仅让 Table 模块在经过拆分后更加清晰,更重要的是不影响老版本用户的体验。在 1.9 版本中,已经 merge 了大部分当初从 Blink 开源出来的 SQL 功能。 除了架构升级之外,Table 模块在 1.9 版本还做了几个相对比较大的重构和新功能,包括: FLIP-37:重构 Table API 类型系统 FLIP-29:Table 增加面向多行多列操作的 API FLINK-10232:初步的 SQL DDL 支持 FLIP-30:全新的统一的 Catalog API FLIP-38:Table API 增加 Python 版本 批处理改进 Flink的批处理功能在 1.9 版本有了重大进步,首当其冲的是优化批处理的错误恢复代价:FLIP-1(Fine Grained Recovery from Task Failures),从这个 FLIP 的编号就可以看出,该优化其实很早就已经提出,1.9 版本终于有机会将 FLIP-1 中未完成的功能进行了收尾。 在新版本中,如果批处理作业有错误发生,那么 Flink 首先会去计算这个错误的影响范围,即 Failover Region。因为在批处理作业中,有些节点之间可以通过网络进行Pipeline 的数据传输,但其他一些节点可以通过 Blocking 的方式先把输出数据存下来,然后下游再去读取存储的数据的方式进行数据传输。 如果算子输出的数据已经完整的进行了保存,那么就没有必要把这个算子拉起重跑,这样一来就可以把错误恢复控制在一个相对较小的范围里。 如果作业极端一点,在每一个需要Shuffle 的地方都进行数据落盘,那么就和 MapReduce 以及 Spark 的行为类似了。只是 Flink 支持更高级的用法,你可以自行控制每种 Shuffle 是使用网络来直连,还是通过文件落盘来进行。 流处理改进 这个版本增加了一个非常实用的功能,即 FLIP-43(State Processor API)。Flink 的 State 数据的访问,以及由 State 数据组成的 Savepoint 的访问一直是社区用户呼声比较高的一个功能。 这次的 State Processor API 则提供了更加灵活的访问手段,也能够让用户完成一些比较黑科技的功能: 用户可以使用这个 API 事先从其他外部系统读取数据,把它们转存为 Flink Savepoint 的格式,然后让 Flink 作业从这个 Savepoint 启动。这样一来,就能避免很多冷启动的问题。 使用 Flink 的批处理 API 直接分析State 的数据。State 数据一直以来对用户是个黑盒,这里面存储的数据是对是错,是否有异常,用户都无从而知。有了这个 API 之后,用户就可以像分析其他数据一样,来对 State 数据进行分析。 脏数据订正。假如有一条脏数据污染了你的 State,用户还可以使用这个 API 对这样的问题进行修复和订正。 状态迁移。当用户修改了作业逻辑,想复用大部分原来作业的 State,但又希望做一些微调。那么就可以使用这个 API 来完成相应的工作。 Hive 集成 在 1.9 版本中,通过 FLIP-30 提出的统一的 Catalog API 的帮助,目前 Flink 已经完整打通了对 Hive Meta Store 的访问。同时,也增加了 Hive 的 Connector,目前已支持 CSV, Sequence File, Orc, Parquet 等格式。用户只需要配置 HMS 的访问方式,就可以使用 Flink 直接读取 Hive 的表进行操作。在此基础之上,Flink 还增加了对 Hive 自定义函数的兼容,像 UDF, UDTF和 UDAF,都可以直接运行在Flink SQL里。 Flink WebUI 修改 组件使用了最新的稳定版本的 Angular。 发布说明

优秀的个人博客,低调大师

Spring 框架文档之 Web —— Servlet 技术栈

Spring Web MVC DispatcherServlet 使用 Java 配置或 web.xml 根据 Servlet 规范进行声明和映射。 然后使用 Spring 配置来发现请求映射、视图解析、异常处理等所需的委托组件。 Servlet 配置 public class MyWebApplicationInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletCxt) { // Load Spring web application configuration AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext(); ac.register(AppConfig.class); ac.refresh(); // 注册并初始化 DispatcherServlet DispatcherServlet servlet = new DispatcherServlet(ac); ServletRegistration.Dynamic registration = servletCxt.addServlet("app", servlet); registration.setLoadOnStartup(1); registration.addMapping("/app/*"); } } 或者 public class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[] { RootConfig.class };//没有用 null 代替 } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[] { App1Config.class }; } @Override protected String[] getServletMappings() { return new String[] { "/app1/*" }; } @Override protected void customizeRegistration(Dynamic registration) { registration.setInitParameter("enableLoggingRequestDetails", "true"); } } 处理过程 在请求中搜索 WebApplicationContext 并将其绑定为控制器和流程中的其他元素可以使用的属性 将语言环境解析器绑定到请求,以便让流程中的元素解析处理请求时使用的语言环境(呈现视图、准备数据等) 主题解析器被绑定到让视图等元素决定使用哪个主题的请求 如果指定了 multipart 文件解析器,将检查请求的 multipart。找到则将请求封装在 MultipartHttpServletRequest中 搜索适当的处理程序。找到则执行与处理程序(预处理程序、后处理程序和控制器)相关联的执行链,以便准备模型或呈现 如果是返回模型,则呈现视图。如果没有返回模型,则不会呈现视图,因为请求已经被执行了 特殊 Bean HandlerMapping —— 将请求映射到带有前置和后置拦截器的处理程序。细节 主要实现者 RequestMappingHandlerMapping 和 BeanNameUrlHandlerMapping 拦截器实现 HandlerInterceptor 的方法 preHandle(..): 在处理程序之前执行 postHandle(..): 在处理程序之后执行 afterCompletion(..): 在请求完成之后执行 public interface HandlerMapping { /** * 将 HttpServletRequest 映射到 Handler,并将匹配的 HandlerInterceptor 绑定到 HandlerExecutionChain */ HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception; } public class HandlerExecutionChain { private final Object handler; private HandlerInterceptor[] interceptors; } HandlerAdapter —— 辅助 DispatcherServlet 调用映射到请求的处理程序。控制 public interface HandlerAdapter { /** * 使用给定 handler 处理请求,返回模型数据和视图名字封装的 ModelAndView */ ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; } /** * 字符和 Map 封装成的对象 */ public class ModelAndView { private Object view; private ModelMap model; } ViewResolver —— 将从处理程序返回的字符串视图名称解析为要呈现给响应的实际视图 InternalResourceViewResolver —— 将视图解析为 Web 应用的内部资源 UrlBasedViewResolver —— 直接根据视图的名称解析视图 ContentNegotiatingViewResolver —— 根据请求文件名或 Accept 标头解析视图 FreeMarkerViewResolver —— 将视图解析为 FreeMarker 模板 ResourceBundleViewResolver —— 将视图解析为资源属性文件 AbstractCachingViewResolver —— 抽象的视图解析器类,提供了缓存视图的功能 public interface ViewResolver { /** * 根据指定的视图名称解析返回 */ View resolveViewName(String viewName, Locale locale) throws Exception; } public interface View { /** * 根据指定的模型数据渲染视图 */ void render(@Nullable Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception; } HandlerExceptionResolver —— 解析异常的策略,可能将异常映射到处理程序、HTML 错误视图或其他目标 SimpleMappingExceptionResolver —— 异常类名称和错误视图名称间的映射 DefaultHandlerExceptionResolver —— 解析 Spring MVC 引发的异常,并将它们映射到 HTTP 状态代码 ResponseStatusExceptionResolver —— 使用 @ResponseStatus 解析异常,并将它们映射到指定 HTTP 状态代码 ExceptionHandlerExceptionResolver —— 在 @Controller 或 @ControllerAdvice 类调用 @ExceptionHandler 解析异常 @RestController public class ErrorController { @RequestMapping(path = "/error") public Map<String, Object> handle(HttpServletRequest request) { Map<String, Object> map = new HashMap<String, Object>(); map.put("status", request.getAttribute("javax.servlet.error.status_code")); map.put("reason", request.getAttribute("javax.servlet.error.message")); return map; } } LocaleResolver —— 提供国际化的视图,解析客户端本地环境 ThemeResolver —— 提供个性化的布局,解析 web 应用程序可以使用的主题 MultipartResolver —— 提供表单文件上传,解析 multi-part 请求 注解 Controller 声明配置 —— 激活 @Controller 的自动检测 @Configuration @ComponentScan("org.example.web") public class WebConfig { // ... } 请求映射 —— @RequestMapping 完成请求到 Controller 方法的映射 变种:@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping 通过 @PathVariable 访问 URI 变量(支持置于类和方法上) {varName:regex} 使用正则表达式声明 URI 变量 consumes 指定请求的 Content-Type 来限制请求的映射 produces 指定请求头的 Accept 来限制请求的映射 params 指定请求的参数 headers 指定请求的请求头 @RestController @RequestMapping("/persons") class PersonController { @GetMapping("/{id}") public Person getPerson(@PathVariable Long id) { // ... } @GetMapping("/{name:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{ext:\\.[a-z]+}") public void handle(@PathVariable String version, @PathVariable String ext) { // ... } @PostMapping(path = "/pets", consumes = "application/json") public void addPet(@RequestBody Pet pet) { // ... } @GetMapping(path = "/pets/{petId}", produces = "application/json;charset=UTF-8") @ResponseBody public Pet getPet(@PathVariable String petId) { // ... } @GetMapping(path = "/pets/{petId}", params = "myParam=myValue") public void findPet(@PathVariable String petId) { // ... } @GetMapping(path = "/pets", headers = "myHeader=myValue") public void findPet(@PathVariable String petId) { // ... } @PostMapping @ResponseStatus(HttpStatus.CREATED) public void add(@RequestBody Person person) { // ... } } 异常处理 @Controller public class SimpleController { // ... @ExceptionHandler public ResponseEntity<String> handle(IOException ex) { // ... } } ControllerAdvice —— 全局异常处理、全局数据预处理、全局数据绑定 @ControllerAdvice(basePackages = "com.cc.controller") public class SpringControllerAdvice { @ExceptionHandler(RuntimeException.class) public ModelAndView runtimeException(RuntimeException e) { return new ModelAndView("error"); } } @ControllerAdvice(basePackages = "com.cc.controller") public class SpringControllerAdvice { @InitBinder public void globalInitBinder(WebDataBinder binder) { binder.addCustomFormatter(new DateFormatter("yyyy-MM-dd")); } } @ControllerAdvice(basePackages = "com.cc.controller") public class SpringControllerAdvice { @ModelAttribute(value = "message") public String globalModelAttribute() { return "this is from model attribute"; } } MVC 配置 @EnableWebMvc 激活 实现 WebMvcConfigurer 添加功能 重写 addFormatters 进行类型转换 重写 getValidator 自定义全局 Validator 实例,也可以通过 @InitBinder 添加 @Controller public class MyController { @InitBinder protected void initBinder(WebDataBinder binder) { binder.addValidators(new FooValidator()); } } 重写 addInterceptors 添加拦截器 重写 configureContentNegotiation 配置请求的媒体类型 重写 configureMessageConverters 配置消息转换器 重写 addViewControllers 添加视图控制器 重写 configureViewResolvers 配置视图解析器 重写 addResourceHandlers 添加静态资源处理器 重写 configureDefaultServletHandling 配置默认 Servlet 处理器 重写 configurePathMatch 配置路径匹配 @Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { // ... } @Override public Validator getValidator(); { // ... } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LocaleChangeInterceptor()); registry.addInterceptor(new ThemeChangeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**"); registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*"); } @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.mediaType("json", MediaType.APPLICATION_JSON); configurer.mediaType("xml", MediaType.APPLICATION_XML); } @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() .indentOutput(true) .dateFormat(new SimpleDateFormat("yyyy-MM-dd")) .modulesToInstall(new ParameterNamesModule()); converters.add(new MappingJackson2HttpMessageConverter(builder.build())); converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build())); } @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("home"); } @Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.enableContentNegotiation(new MappingJackson2JsonView()); registry.jsp(); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**") .addResourceLocations("/public", "classpath:/static/") .setCachePeriod(31556926); } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable();//或者 configurer.enable("myCustomDefaultServlet"); } @Override public void configurePathMatch(PathMatchConfigurer configurer) { configurer .setUseSuffixPatternMatch(true) .setUseTrailingSlashMatch(false) .setUseRegisteredSuffixPatternMatch(true) .setPathMatcher(antPathMatcher()) .setUrlPathHelper(urlPathHelper()) .addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class)); } @Bean public UrlPathHelper urlPathHelper() { //... } @Bean public PathMatcher antPathMatcher() { //... } } 视图技术 Thymeleaf —— 现代化服务器端 Java 模板引擎,支持原生 HTML,可在浏览器中双击预览 FreeMarker —— 用于生成从 HTML 到电子邮件等类型文本输出的模板引擎 @Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { @Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.freemarker(); } // Configure FreeMarker... @Bean public FreeMarkerConfigurer freeMarkerConfigurer() { FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); configurer.setTemplateLoaderPath("/WEB-INF/freemarker"); return configurer; } } <#import "/spring.ftl" as spring/> <html> ... <form action="" method="POST"> Name: <@spring.bind "myModelObject.name"/> <input type="text" name="${spring.status.expression}" value="${spring.status.value?html}"/><br> <#list spring.status.errorMessages as error> <b>${error}</b> <br> </#list> <br> ... <input type="submit" value="submit"/> </form> ... </html> Groovy Markup —— 生成类似于 XML 的标记 @Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { @Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.groovy(); } // Configure the Groovy Markup Template Engine... @Bean public GroovyMarkupConfigurer groovyMarkupConfigurer() { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath("/WEB-INF/"); return configurer; } } yieldUnescaped '<!DOCTYPE html>' html(lang:'en') { head { meta('http-equiv':'"Content-Type" content="text/html; charset=utf-8"') title('My page') } body { p('This is an example of HTML contents') } } 脚本视图 @Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { @Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.scriptTemplate(); } @Bean public ScriptTemplateConfigurer configurer() { ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer(); configurer.setEngineName("nashorn"); configurer.setScripts("mustache.js"); configurer.setRenderObject("Mustache"); configurer.setRenderFunction("render"); return configurer; } } <html> <head> <title>{{title}}</title> </head> <body> <p>{{body}}</p> </body> </html> JSP <form:form> <table> <tr> <td>First Name:</td> <td><form:input path="firstName"/></td> </tr> <tr> <td>Last Name:</td> <td><form:input path="lastName"/></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Save Changes"/> </td> </tr> </table> </form:form> RSS and Atom public class SampleContentAtomView extends AbstractAtomFeedView { @Override protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) { // implementation omitted } @Override protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // implementation omitted } } public class SampleContentRssView extends AbstractRssFeedView { @Override protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) { // implementation omitted } @Override protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // implementation omitted } } PDF and Excel public class PdfWordList extends AbstractPdfView { protected void buildPdfDocument(Map<String, Object> model, Document doc, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { List<String> words = (List<String>) model.get("wordList"); for (String word : words) { doc.add(new Paragraph(word)); } } } public class ExcelViewBuilder extends AbstractExcelView { protected void buildExcelDocument(Map<String,Object> model,HSSFWorkbook wb,HttpServletRequest req, HttpServletResponse resp) { // ... } } XSLT @EnableWebMvc @ComponentScan @Configuration public class WebConfig implements WebMvcConfigurer { @Bean public XsltViewResolver xsltViewResolver() { XsltViewResolver viewResolver = new XsltViewResolver(); viewResolver.setPrefix("/WEB-INF/xsl/"); viewResolver.setSuffix(".xslt"); return viewResolver; } } @Controller public class XsltController { @RequestMapping("/") public String home(Model model) throws Exception { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = document.createElement("wordList"); List<String> words = Arrays.asList("Hello", "Spring", "Framework"); for (String word : words) { Element wordNode = document.createElement("word"); Text textNode = document.createTextNode(word); wordNode.appendChild(textNode); root.appendChild(wordNode); } model.addAttribute("wordList", root); return "home"; } } <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" omit-xml-declaration="yes"/> <xsl:template match="/"> <html> <head><title>Hello!</title></head> <body> <h1>My First Words</h1> <ul> <xsl:apply-templates/> </ul> </body> </html> </xsl:template> <xsl:template match="word"> <li><xsl:value-of select="."/></li> </xsl:template> </xsl:stylesheet>

优秀的个人博客,低调大师

Spring 框架文档之核心技术—— Resource

Resource Resource 接口定义 public interface Resource extends InputStreamSource { /** * 返回此资源的 URL 句柄 */ URL getURL() throws IOException; /** * 返回此资源的 URI 句柄 */ URI getURI() throws IOException; /** * 返回此资源的 File 句柄 */ File getFile() throws IOException; /** * 创建此资源的关联资源 */ Resource createRelative(String relativePath) throws IOException; } public interface InputStreamSource { /** * 返回底层资源内容的 InputStream */ InputStream getInputStream() throws IOException; } 内置 Resource 实现者 UrlResource —— 封装 java.net.URL,用于访问通过URL访问的任何对象,例如 file:、http:、ftp: 等 ClassPathResource —— 使用线程上下文类加载器、给定的类加载器或给定的类从类路径加载资源。如 classpath: FileSystemResource —— 从文件系统加载资源 ServletContextResource —— 从 Web 应用根目录的相对路径中加载资源,支持 URL、流、File(资源位于文件系统)访问 InputStreamResource —— 在没有特定的资源实现时使用 ByteArrayResource —— 从任何给定的字节数组加载资源 ResourceLoader 返回资源类型确认 //对于 ClassPathXmlApplicationContext, 返回 ClassPathResource //对于 FileSystemXmlApplicationContext, 返回 FileSystemResource //对于 WebApplicationContext, 返回 ServletContextResource Resource template = ctx.getResource("some/resource/path/myTemplate.txt"); //指定 classpath:,返回 ClassPathResource Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt"); //指定 file:、http:,返回 UrlResource Resource template = ctx.getResource("file:///some/resource/path/myTemplate.txt"); Resource template = ctx.getResource("https://myhost.com/resource/path/myTemplate.txt"); 与 ApplicationContext 协作 ApplicationContext ctx = new ClassPathXmlApplicationContext("conf/appContext.xml"); //注意:FileSystemXmlApplicationContext 强制将 FileSystemResource 路径当作相对路径 ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/appContext.xml"); //如要使用绝对路径,推荐使用 file: 形式的 UrlResource ApplicationContext ctx = new FileSystemXmlApplicationContext("file:///conf/context.xml");

优秀的个人博客,低调大师

借助URLOS快速安装MixPHP-2.0.1框架

环境需求 最低硬件配置:1核CPU,1G内存(1+1)提示:如果你的应用较多,而主机节点的硬件配置较低,建议在部署节点时开通虚拟虚拟内存; 生产环境建议使用2G或以上内存; 推荐安装系统:Ubuntu-16.04、Ubuntu-18.04、CentOS7.X、Debian9X的64位的纯净的操作系统; URLOS安装 curl -LO www.urlos.com/iu && sh iu MixPHP安装流程 登录URLOS系统后台,在应用市场中搜索“MixPHP”,找到之后,直接点击安装按钮 填写服务名称、选择运行节点、服务端口、选择智能部署 填写网站域名、ssh密码(这里的密码是root密码) 然后点击“提交”按钮,等待部署完成; 访问网站访问:www.aaa.com:8088(这里是自己的域名) 登录sftp 网站根目录在 data/www/mix/

优秀的个人博客,低调大师

Scrapy框架的使用之Spider的用法

本文来自云栖社区官方钉群“Python技术进阶”,了解相关信息可以关注“Python技术进阶”。 在Scrapy中,要抓取网站的链接配置、抓取逻辑、解析逻辑里其实都是在Spider中配置的。在前一节实例中,我们发现抓取逻辑也是在Spider中完成的。本节我们就来专门了解一下Spider的基本用法。 1.Spider运行流程 在实现Scrapy爬虫项目时,最核心的类便是Spider类了,它定义了如何爬取某个网站的流程和解析方式。简单来讲,Spider要做的事就是如下两件: 定义爬取网站的动作; 分析爬取下来的网页。 对于Spider类来说,整个爬取循环过程如下所述: 以初始的URL初始化Request,并设置回调函数。当该Request成功请求并返回时,Response生成并作为参数传给该回调函数。 在回调函数内分析返回的网页内容。返回结果有两种形

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册