简体   繁体   English

Google Console Chrome jQuery 从 HTML 中提取名称和 URL

[英]Google Console Chrome jQuery extract the name and URL from HTML

I wish to extract all links and text from the HTML source code and add it to a multidimensional array using the google come console我希望从 HTML 源代码中提取所有链接和文本,并使用 google come 控制台将其添加到多维数组中

Code snippet -- repeated 10 times代码片段——重复 10 次

<div class="Contentx">
    <a style='text-decoration:none;' href='Tate-Tea.com'>
        <h2>Tate Tea<br>
            <span class='Fis'>Tate-Tea.com</a></span>
        </h2>
        </span>

The result would be an array结果将是一个数组

{'Tate-Tea.com','Tate Tea'}

I am having a difficulty finding a style='text-decoration我很难找到a style='text-decoration

So I guess match所以我猜匹配

Loop around and append to the array ..循环并附加到数组..

 Var list = []

 document.querySelectorAll('a[style.textDecoration:none]')
.each(function(){
 var URL = $(this).attr("href");
 var URL_name =  alert($(this).text());
..# append to list 
list.push ({   URL : '', 
URL_name : ''

}}

});

document.querySelector('a[style]').href document.querySelector('a[style]').text I can get one of them by using following document.querySelector('a[style]').href document.querySelector('a[style]').text我可以使用以下方法获取其中之一

First find all a tag and then manipulate those of that meats this style.textDecoration == "none" condition.首先找到所有标签,然后操纵那些符合style.textDecoration == "none"条件a标签。

Try this one:试试这个:

 var list = [] document.querySelectorAll('a') .forEach(function (tag) { if (tag.style.textDecoration == "none") { var URL = tag.getAttribute("href"); var URL_name = alert(tag.text); list.push({ URL: URL, URL_name: URL_name }) } }); console.log(list);
 <div class="Contentx"> <a style='text-decoration:none;' href='Tate-Tea.com'> <h2>Tate Tea<br><span class='Fis'>Tate-Tea.com</a></span></h2> </span> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM