<!DOCTYPE html>
<html>
<head>
<title>获取网页内容示例</title>
</head>
<body>
<div id="content"></div>
<script>
const contentDiv = document.getElementById('content');
// 要获取内容的网页的URL
const url = 'https://example.com'; //将这里的url改为自己的
// 使用 fetch API 获取网页内容
fetch(url)
.then(response => {
// 将响应数据转换为文本
return response.text();
})
.then(data => {
// 在这里处理响应数据
contentDiv.textContent = data;
})
.catch(error => {
// 在这里处理错误
console.error('获取内容发生错误:', error);
});
</script>
</body>
</html>
{/collapse-item}
评语 (0)