網頁內容抓取工具:ReactiPy

dwd4 9年前發布 | 14K 次閱讀 ReactiPy 網絡爬蟲

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.baiduhome.net/lib/view/home/1427853387256

 本文由用戶 dwd4 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!