使用书签进行网页抓取?
我想使用一个小书签来收集来自不同网页的一些资源。
即,我不想使用一些浏览器扩展来从页面获取 html 元素,而是使用一些 javascript bookmarklet 从网站捕获代码。
[编辑] 如何使用 JavaScript 书签从页面获取 html 元素?
问题是关于使用 bookmarklet 获取 html 内部代码,而不是一般的 bookmarklet。
I'd like to use a bookmarklet to gather toghether a few resouces from different webpages.
i.e, instead of using some browser extensions to get the html elements from the pages, I would like to use some javascript bookmarklet to capture the code from the sites.
[Edit] How do I get the html elements from the page with JavaScript bookmarklet?
The question is about getting the html inner code with bookmarklet, not about bookmarklet in general.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要任何库来执行此操作。只需在 Firebug 或 Chrome Inspector 中创建您的功能,然后将其格式化为一行,如下所示:
javascript:(function(){alert(1);})();
将其复制并粘贴到该位置栏并按回车键执行它。更换警报(1);用你的代码。我们将其包装在一个自动执行的匿名函数中,否则您执行的响应将替换网页。
如果您的代码真的很长,您可以将其全部写入外部 javascript 文件中,并且在您看到上面的警报的地方,只需使用 src 创建一个脚本标记并将其附加到页面即可。
You don't need any libraries to do this. Just create your functionality in Firebug or Chrome Inspector and then format it on one line like this:
javascript:(function(){alert(1);})();
Copy and paste this to the location bar and hit enter to execute it. Replace the alert(1); with your code. We wrap it in a self-executing anonymous function or else the response of what you execute would replace the web page.
If your code is really long you can write it all in an external javascript file and where you see the alert above just create a script tag with your src and append it to the page.
您可能会考虑加载 javascript代码,该代码将在有人时执行抓取由于小书签长度限制,您点击了您的小书签。有关访问 DOM 元素的信息,请参阅此参考。
请注意,由于跨框架安全。
You might consider loading javascript code that will perform scraping when someone clicks on your bookmarklet, because of bookmarklet length limitation. On accessing DOM elements see this reference.
Please note, that scraping will only be possible for FRAME/IFRAMEs originated from the same domain as the main window, due to cross frame security.
我制作的这个长脚本将为您提供准确的内容,以及其他一些独特的增强功能:
This long script I made will give you exactly that, as well as a few other unique enhancements: