网页内容抓取工具:ReactiPy

dwd4 9年前

ReactiPy  是 Python 的模块,用来将 React 组件渲染成 HTML 内容。它支持快速加载网页、使搜索引擎更快的抓取网页内容,以达到 SEO 优化的目的。

代码示例:

from reactipy.component import ReactComponent  import os        class HelloWorldComponent(ReactComponent):      path = os.path.join(          os.path.dirname(os.path.abspath(__file__)),          'components/helloworld.js')     component = HelloWorldComponent()     component.render(props=['Hello', 'World'])

Documentation

Installation

pip install reactipy

ReactComponent

Define Component

Define a react component that includes a path pointing to the path of the React Component. JSX is not supported so make sure to compile your jsx templates to js.

from reactipy.component import ReactComponent class HelloWorldComponent(ReactComponent):      path = 'path/to/component.js' 

*** You must specify a path when defining a React Component ***

Create Instance

Create an instance of the component and optionally specifiy a container which will output an id on the component and props_name which will be a global variable that has all the props specified in json

component = HelloWorldComponent(container='helloworld', props_name='HELLO_PROPS')

Arguments:

  • container: [optional] the id of the container.
  • props_name:[optional] the props variable name.

Render Component

Render a component to html on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.

component.render(info=['hello', 'world]) 

Arguments:

  • kwargs: [optional] the props

项目主页:http://www.open-open.com/lib/view/home/1427853387256