使用 JavaScript bookmarklet 获取 Ajax HTML 元素 [英] Get Ajax HTML element by using JavaScript bookmarklet
问题描述
我是 bookmarklet 的新手,不确定可以做多少.我想从网页中获取一些元素,但在我单击某些按钮之前不会显示内容.我可以使用以下非常简单的代码在静态网页上获取一些内容,但是否可以通过创建书签来获取更深层次的元素.
I am new to bookmarklet, not sure how much can be done with this. I want to get some elements from webpage, but the content will not show up till i click some buttons. I was able to get something on static webpage with below very simple code, but will it possible to get deeper elements by creating a bookmarklet.
是否可以使用 javascript bookmarklet 获得深红色圆圈部分?我能够使用 python 模拟用户操作来做到这一点,但我想要更快地获取元素.请分享一些我可以寻找的方向,似乎可以创建书签并快速完成许多事情.
Is it possible to get the deep red circled part with javascript bookmarklet? I was able to do this with python simulate user action, but I want something quicker to get the element. Please share some directions i can look for, it seems bookmarklet can be created and get many things done quickly.
javascript: (function() {
var v = document.getElementById("view_shade").value ;
alert(v);
})();
第一次进入页面时的html:
The html when first enter page:
点击一些按钮后添加的内容,红色部分是我想要获取的元素
Added content after click some buttons, red part is the element i want to get
推荐答案
当然,您可以获得 HTML 的任何部分.
Sure, you can get any part of the HTML.
例如,您可以将 querySelectorAll
与 DOM attributes
属性结合使用.
For example you can use querySelectorAll
for that coupled with DOM attributes
property.
javascript:(function(){
var v = document
.getElementById('view_shade')
.querySelectorAll('[data-guid]')[0]
.attributes["data-guid"]
.value;
alert(v);
})();
<table border="1">
<thead></thead>
<tbody></tbody>
<tr id="view_shade">
<td data-guid="BCC-RED">one</td>
<td>two</td>
</tr>
</table>
根据您当前问题的文本,我认为您不需要 AJAX 来解决此特定问题.
Based on the text of your current question I don't see you need AJAX for this particular issue.
但是在某些情况下,通过书签创建 AJAX 也是可行的,但是,这可能是一个单独的问题,可能取决于 URL、某些服务器问题(例如 CORS 等)等.
But making AJAX via a bookmarklet is doable too upon some conditions, however, it might be a separate issue and might depend on the URL, some server issues (e.g. CORS etc) and so on.
AJAX 的一些基础知识:如何在没有 jQuery 的情况下进行 AJAX 调用?
Some basics of AJAX: How to make an AJAX call without jQuery?
这篇关于使用 JavaScript bookmarklet 获取 Ajax HTML 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!