鉴于我的GM脚本运行的这个示例HTML,我想创建一个代码来捕获http://www.mycharactersID.com/ID=234223
JavaScript获得234223后,页面上的其他ID。然后在新选项卡中使用不同的链接打开它们。我的意思是HTML中的所有ID。
示例:window.open("http://www.mycharactersID.com/TalkID=234223")
。
Burada takılan <b>12</b> karakter bulunmaktadır.<br><br>
<table border="0" cellpadding="2" cellspacing="0" width="400">
<tbody><tr>
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=1858480">Alexandra Anthony</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr class="DarkColumnHL">
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=2624518">Igor Arnaudov</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr>
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=1318025">Ashanti Dunn</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr class="DarkColumnHL">
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=621305">Abigail Eliopoulos</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr>
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=1853122">Fynn Linus Hargasser</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr class="DarkColumnHL">
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=2347156">Sabela Hernani</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr>
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=595514">Maaja Jürisson</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr class="DarkColumnHL">
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=1329193">Sixtine Karakaya</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr>
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=156315">Umut Koç</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr class="DarkColumnHL">
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=821852">Shanice Manning</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr>
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=393396">Demircan Özdal</a>
</td>
<td align="right" width="158">
</td>
</tr>
<tr class="DarkColumnHL">
<td width="234">
<a href="CharacterDetails.asp?action=view&CharacterID=550724">Mélodie Stavropoulos</a>
</td>
<td align="right" width="158">
</td>
</tr>
</tbody></table>
<br>
Not: En fazla 100 karakter listelenmektedir.<br><br>
谢谢。
答案 0 :(得分:2)
以下是使用JQuery的解决方案:
$('table tr td a[href^="http://www.mycharactersID.com/ID="]').each(function(){
var regExp=/id=(\d+)/i;
var matches=$(this).attr('href').match(regExp);
if(matches)
{
window.open('url/ID='+parseInt(matches[1]), w_name, w_params);
}
});
它应该有用。
答案 1 :(得分:1)
这是一个完整的GM脚本,可以使用。
请注意,它会立即打开所有新标签页。要按顺序打开,您需要像this answer一样排队。
// ==UserScript==
// @name _Open lots of tabs
// @include http://mycharactersID.com/YOUR_PATH/*
// @include http://www.mycharactersID.com/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==
$("td > a[href*='CharacterID']").each ( function () {
var ID = this.href.match (/CharacterID=(\d+)$/i);
if (ID && ID.length > 1) {
ID = ID[1];
window.open ("http://www.mycharactersID.com/TalkID=" + ID, "_blank");
}
} );
答案 2 :(得分:0)
我不确定如何打开链接但是捕获数据很容易。
var idArray = document.body.innerHTML.match(/"http:\/\/www\.mycharactersID\.com\/ID=([0-9]*)"/g); //captures the entire link
for(var i = 0; i < idArray.length; i++){
idArray[i] = idArray[i].replace(/"http:\/\/www\.mycharactersID\.com\/ID=([0-9]*)"/, "$1"); //Now just the ID part
}
经过测试,似乎正在运作。
答案 3 :(得分:0)
这是有效的
html
<a href="http://www.mydomain.com/ID=25645" onclick="OpenMyPage(this); return false;">Click HyperLink</a>
的javascript
function OpenMyPage(hyperlink) {var source = hyperlink.attributes.href.value; var pattern = new RegExp("(\\d+)$"); source.match(pattern); alert(RegExp.$1);}