我需要使用React渲染:
class App extends Component {
render() {
return (
<div className="App">
{ ReactDOM.render(str) }
</div>
);
}
}
但是在没有分配容器的情况下不允许这样使用。
如何实现?
答案 0 :(得分:1)
请参见ReactDOMServer
,尤其是.renderToString
和.renderToStaticMarkup
方法。
类似
[<div aria-live="assertive" id="gs_md_cita-l"></div>]
[<div aria-live="assertive" id="gs_md_cita-l"></div>]
[<div aria-live="assertive" id="gs_md_cita-l"></div>]
请记住,以上内容将转译呈现的html,您实际上将看到代码。如果要将渲染的html用作 live html,则需要使用dangerouslySetInnerHTML
属性。
import bs4
import urllib
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import urllib.request
class Scraper():
def __init__(self, url, maxP):
self.url= url
self.maxP = maxP
def f(self):
for i in range(0,1000,100):
if (self.maxP<i):
pageSize=i
for j in range(0, pageSize, 100):
S_url=self.url + "&cstart=" + str(j) +"&pagesize=100"
my_url = uReq(S_url)
page_html = my_url.read()
my_url.close()
page_soup = soup(page_html, "lxml")
aTag = page_soup.findAll('td', {'class': 'gsc_rsb_std'})
Titles = page_soup.findAll('td', {'class': 'gsc_a_t'})
Citations = page_soup.findAll('td', {'class': 'gsc_a_c'})
Years = page_soup.findAll('td', {'class': 'gsc_a_y'})
info_page = page_soup.findAll('a', {'class' : 'gsc_a_at'})
for author in info_page:
Author_names_link = author["data-href"]
user=Author_names_link[53:65]
n_input=Author_names_link[-12:]
n_author_url="https://scholar.google.com.au
/citations?user="+user+"&hl=en#d=gs_md_cita-
d&u=%2Fcitations%3Fview_op%3Dview_citation%26hl%3Den%26user%3D"+user+"%26cit
ation_for_view%3D"+user+"%3A"+n_input+"%26tzom%3D-330"
author_url=uReq(n_author_url)
n_page=author_url.read()
author_url.close()
n_page_soup=soup(n_page, "html.parser")
n_tag=n_page_soup
m_tag=n_tag.findAll('div', {'id': 'gs_top'})
for i in m_tag:
p_tag=i.findAll('div', {'data-h': '800'})
for j in p_tag:
q_tag=j.findAll('div', {'id': 'gs_md_cita-d'})
for k in q_tag:
r_tag=k.findAll('div', {'id': 'gs_md_cita- d-bdy'})
for l in r_tag:
s_tag=l.findAll('div', {'id': 'gs_md_cita-l'})
答案 1 :(得分:0)
ReactDOM.render
是一个带有两个参数的函数,分别表示要呈现的内容和呈现的位置...
import React from 'react';
import ReactDOM from 'react-dom';
const str = 'Hello There.'
ReactDOM.render(str, document.getElementById('root'));
第一个arg是str
,第二个是渲染document.getElementById('root')
答案 2 :(得分:0)
使用所需的名为App的组件,代码应如下所示:
import React from 'react';
import ReactDOM from 'react-dom';
class App extends Component {
const str = 'Hello World';
render() {
return <h1>{str}<h1/>;
}
}
ReactDOM.render(<App />,document.getElementById('root'));