伪造者由于某种原因无法获取数据
我创建了一个React应用程序,该应用程序将以下输出作为HTML:
import './App.css';
import Home from './Home';
function App() {
return (
<div className="Apps">
<strong>"root1"</strong>
<div className="content">
<p>"root"</p>
</div>
</div>
);
}
export default App;
我的目标是从&lt; strong&gt;
标签中基本上检索“ root1”。我编写了以下代码,但没有检索数据:
const puppeteer = require("puppeteer")
const fs = require("fs/promises")
async function start() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto("https://.herokuapp.com/")
const names = await page.evaluate(() => {
return Array.from(document.querySelectorAll(".Apps strong"), els => els.map(el => el.textContent))
})
await fs.writeFile("names.txt", names.join("\r\n"))
await browser.close()
}
start()
当我运行脚本时,会创建一个新的文本文件,但它是空的,而不是显示“ root1”。有人可以帮我吗?感谢您的时间!
I have created a react app that gives the following output as HTML:
import './App.css';
import Home from './Home';
function App() {
return (
<div className="Apps">
<strong>"root1"</strong>
<div className="content">
<p>"root"</p>
</div>
</div>
);
}
export default App;
My goal here is to basically retrieve "root1" from the <strong>
tag under the Apps class. I have written the following code but it doesn't retrieve the data:
const puppeteer = require("puppeteer")
const fs = require("fs/promises")
async function start() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto("https://.herokuapp.com/")
const names = await page.evaluate(() => {
return Array.from(document.querySelectorAll(".Apps strong"), els => els.map(el => el.textContent))
})
await fs.writeFile("names.txt", names.join("\r\n"))
await browser.close()
}
start()
When I run the script, a new text file is created but it is empty instead of showing "root1". Can someone help me? Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Ggorlen给我的正确答案应该是这样:
谢谢!
The correct answer was given to me by @ggorlen, it should be like this:
Thanks!