javascript - 如何在javascript中的链接中获取元素?
问题描述
我想制作一个模拟器,告诉您该网站上特定用户名的个人资料的最后评论。我想从该链接(链接为“ https://scratch.mit.edu/users/oreyelephant/ ”)中定位特定的类或ID ,并检测最新评论的简单文本,并将其放入一个div或段落标签。对于这个声明,我想在控制台中声明关于我的文本。这是我所拥有的:
var link = "https://scratch.mit.edu/users/oreyelephant/"
var aboutMe = link.getAttribute("editable read");
console.log(aboutMe);
我拥有“可编辑读取”的 getAttribute 的原因是因为这是我要获取其文本的类的名称。我试图获取 text/innerText 的地方
解决方案
要了解用户,请不要直接尝试这样做,请使用临时 API。
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', 'https://api.scratch.mit.edu/users/oreyelephant', true);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
var response = JSON.parse(xmlhttp.responseText);
console.log(response["profile"]["bio"])
}
};
推荐阅读
- swift - VIO 错误回调 - 检测到 3d 条码 - Swift
- angular - 可折叠的 mat-sidenav 菜单调整内容不起作用
- html - Bootstrap 4 导航栏没有切换
- flutter - 在 Flutter 中使用 Provider 包实现运行时多态性
- neural-network - OpenVINO 工具包如何对 FPGA 进行编程?
- antlr - 我可以添加不能在词法分析器规则中应用的语法词吗?
- ios - Swift:具有相同函数名的协议和基类
- jenkins - Jenkins 为管道构建选择变更集作业
- css - React JS:如何为有条件渲染的组件设置动画?
- python - 使用 Brief、BRISK、AKAZE 和 FREAK 检测到零关键点