小编alm*_*ann的帖子

无法使用服务器端渲染访问DOM - 反应0.14.1,react-dom 0.14.1和react-router 1.0.0-rc3

我无法使用react,react-dom和react-router的服务器实现来访问DOM.我要么具有ReferenceError:未定义文档,要么浏览器历史记录需要DOM错误.

服务器条目:

module.exports = function( req, res, next ) {
  match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
    if (error) {
        res
            .status(500)
            .send(error.message);
    } else if (redirectLocation) {
        res.redirect(302, redirectLocation.pathname + redirectLocation.search);
    } else if (renderProps) {
        res
            .status( 200 )
            .set( 'Content-Type', 'text/html' )
            .send( '<!doctype html>' +
                renderToString(
                    [ <RoutingContext {...renderProps} />,
                    <HtmlDocument /> ]
                )
            );
    } else {
        res
            .status(404)
            .send('Not found');
    }
  })
};
Run Code Online (Sandbox Code Playgroud)

client.js:

import { render } from 'react-dom';
import …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router

7
推荐指数
1
解决办法
4212
查看次数

BeautifulSoup:RuntimeError:超出最大递归深度

我无法使用BeautifulSoup避免最大递归深度Python RuntimeError.

我试图通过嵌套的代码部分进行递归并提取内容.美化的HTML看起来像这样(不要问为什么它看起来像这:)):

<div><code><code><code><code>Code in here</code></code></code></code></div>
Run Code Online (Sandbox Code Playgroud)

我传递汤对象的功能是:

def _strip_descendent_code(self, soup):
    sys.setrecursionlimit(2000)
    # soup = BeautifulSoup(html, 'lxml')
    for code in soup.findAll('code'):
        s = ""
        for c in code.descendents:
            if not isinstance(c, NavigableString):
                if c.name != code.name:
                    continue
                elif c.name == code.name:
                    if isinstance(c, NavigableString):
                        s += str(c)
                    else:
                        continue
        code.append(s)
    return str(soup)
Run Code Online (Sandbox Code Playgroud)

您可以看到我正在尝试增加默认的递归限制,但这不是一个解决方案.我已经增加到C达到计算机内存限制的程度,上面的功能永远不会起作用.

任何帮助让这个工作,并指出错误/ s将非常感激.

堆栈跟踪重复此:

  File "/Users/almccann/.virtualenvs/evernoteghost/lib/python3.4/site-packages/bs4/element.py", line 1234, in find
    l = self.find_all(name, attrs, recursive, text, 1, **kwargs)
  File "/Users/almccann/.virtualenvs/evernoteghost/lib/python3.4/site-packages/bs4/element.py", line 1255, in find_all
    return self._find_all(name, attrs, text, limit, …
Run Code Online (Sandbox Code Playgroud)

python recursion runtime-error beautifulsoup

6
推荐指数
2
解决办法
4043
查看次数