如何阅读使用Firefox插件的特定网址的HTML内容? [英] How to read html content of a specific URL using Firefox addon?
问题描述
我想创建一个插件,它将加载特定网址的html内容,并保存该网页的特定行,然后移动到该网址。我在Mozila.org上阅读了很多关于网页内容的东西,但是我不懂如何阅读html内容。
在不知道页面和URL的情况下,我无法创建一个完整的解决方案,但是这里有一个例子Greasemonkey脚本我写的是类似的东西。
该脚本适用于DZone上的Java文章。当文章链接到源代码时,它会重定向到这个源代码页:
// == UserScript ==
// @name DZone源
// @namespace com.kwebble
// @description直接转到DZone文章的源代码。
// @include http://java.dzone.com/*
// @version 1
// @grant none
// == / UserScript ==
var node = document.querySelector('a [target =_ blank]');
if(node!== null){
document.location = node.getAttribute('href');
code
$ b >
- 安装 Greasemonkey ,还没有。
- 创建脚本,类似于我的。将@include的值设置为包含要查找的URL的页面。
- 必须确定哪些内容可以用目标URL标识页面部分,然后更改脚本以找到该URL。对于我的脚本,它是一个_blank目标的链接。
保存脚本后,通过链接访问该页面。 Greasemonkey应该执行你的脚本并重定向浏览器。
$这个搜索脚本标签的文本就像你描述的和重定向的。
// == UserScript ==
// @name测试
// @namespace com.kwebble
/ / @include your_page
// @version 1
// @grant none
// == / UserScript ==
var nodes = document.getElementsByTagName('脚本'),
i,匹配;
$ b $ for(i = 0; i< nodes.length; i ++){
if(nodes.item(i).innerHTML!==''){
matches = nodes.item(i).innerHTML.match(/windows\.location =(。*?)。php; /);
if(matches!== null){
document.location = matches [1];
code $
$ b 正则表达式查找网址可能需要进行一些调整以匹配确切的网页内容。
I want to create an addon which will load html content of a specific url and save a specific line of that page and then move to that url. I read a lot of things on Mozila.org about content of a web page but I don't understand how to read the html content.
解决方案 Without knowing the page and URL to find on it I can't create a complete solution, but here's an example Greasemonkey script I wrote that does something similar.
This script is for Java articles on DZone. When an article has a link to the source, it redirects to this source page:
// ==UserScript==
// @name DZone source
// @namespace com.kwebble
// @description Directly go to the source of a DZone article.
// @include http://java.dzone.com/*
// @version 1
// @grant none
// ==/UserScript==
var node = document.querySelector('a[target="_blank"]');
if (node !== null) {
document.location = node.getAttribute('href');
}
Usage:
- Install Greasemonkey if you haven't yet.
- Create the script, similar to mine. Set the value for @include to the page that contains the URL to find.
- You must determine what identifies the part of the page with the destination URL and change the script to find that URL. For my script it's a link with a target of "_blank".
After saving the script visit the page with the link. Greasemonkey should execute your script and redirect the browser.
[edit]
This searches script tags for text like you described and redirects.
// ==UserScript==
// @name Test
// @namespace com.kwebble
// @include your_page
// @version 1
// @grant none
// ==/UserScript==
var nodes = document.getElementsByTagName('script'),
i, matches;
for (i = 0; i < nodes.length; i++) {
if (nodes.item(i).innerHTML !== '') {
matches = nodes.item(i).innerHTML.match(/windows\.location = "(.*?).php";/);
if (matches !== null){
document.location = matches[1];
}
}
}
The regular expression to find the URL might need some tweaking to match the exact page content.
这篇关于如何阅读使用Firefox插件的特定网址的HTML内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!