首页 > 解决方案 > 需要 javascript react 中给定 URL 的完整呈现文本

问题描述

我有一个奇怪的要求。我正在创建一个平台,艺术家将在其中创建个人资料并展示他们的作品。现在大多数艺术家都有他们以前的唱片或其他一些网站平台,如songkick或他们自己的网站。现在我的客户要求是用户将提供他们过去数据的url或其他东西,系统将通过该网站并根据某些字段获取内容。例如事件数据包含事件/位置/日期

我正在使用 AWS Comprehend 分析数据,现在我陷入困境的部分是获取整个网站数据/文本。

可以说我有一个https://www.something.com的网址。我想去这个网站并在里面获取所有呈现的文本。如果这是不道德的,或者我需要用其他方法做到这一点,请建议我。

我现在正在尝试做的事情并失败了

fetch('https://www.somthing.com').then((response)=>console.log(response))

但这给了我fetch failed type error

我知道首先想到的是使用提供的 url 平台 API,但大多数网站都没有

标签: javascriptreactjsweb-scrapingweb-crawler

解决方案


如果其他人想知道同样的事情,那么我将 node js 与puppeteer库和request库一起使用(已弃用)

傀儡师

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://www.kaiakater.com/shows");
const example = await page.evaluate(() => {
  const temp = Array.from(document.body.getElementsByTagName("*"), (e1) => {});

请求图书馆

const requestFunction = () => {
 request("https://www.instagram.com/", function (error, response, body) {
 console.error("error:", error); 
 // Print the error if one occurred
 console.log("statusCode:", response && response.statusCode); 
 // Print the response 
 status code if a response was received
 console.log("body:", body); // Print the HTML for the Google homepage.
});
};

推荐阅读