[英]Remove all <div> tags with a query
[英]How to remove all URLs based on keywords in the DIV tags
如何刪除DIV標簽中從特定關鍵字過濾掉的特定URL。 假設我有一個這樣的文本:
<div class="target">
https://my-site.com/test1_good.html
https://my-site.com/test1_fake.html
https://my-site.com/test2_good.html
https://my-site.com/test2_fake.html
https://my-site.com/test3_good.html
https://my-site.com/test3_fake.html
</div>
在這里,我希望所有包含關鍵字"_good.html"
URL都可以使結果變為:
<div class="target">
https://my-site.com/test1_good.html
https://my-site.com/test2_good.html
https://my-site.com/test3_good.html
</div>
能做到嗎? 不管使用Javascript,jQuery還是PHP。 謝謝..
這取決於您最初輸出網址的方式。 如果您正在使用PHP並以循環方式輸出它們,則可以使用preg_match()
,否則可以通過如下所示的匹配項來使用JavaScript:
<script>
$(document).ready(function() {
// Fetch the urls
var getCont = $('.target').text();
// Create storage
var getGood = [];
// Loop the urls
$.each(getCont.split('\n'),function(k,v) {
// If contains the string, save to storage
if(v.match(/_good/i))
getGood.push(v);
});
// Tell us about it...
console.log(getGood);
});
</script>
在控制台中,向您提供以下內容:
[
"https://my-site.com/test1_good.html",
"https://my-site.com/test2_good.html",
"https://my-site.com/test3_good.html"
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.