javascript - 从 JSON 对象的 HTML 中解析 img

标签 javascript jquery html json

<分区>

作为 JSON 对象的一部分,我通过 $ajax 获取,如下所示:

$.ajax({
url: 'untitled.php',
type: 'GET',

success: function(data) {

var obj = jQuery.parseJSON( data );
$.each(obj.entry, function(i, data) {
                console.log(data.content);
            });

 }
});

我在我的控制台中为每个 obj.entry 取回(例如):

<table border=\"0\" width=\"100%\">\n    
    <tr>\n        
        <td>\n            
            <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n                
                <tr valign=\"top\" align=\"left\">\n                    \n                        
                    <td align=\"center\" width=\"166\" valign=\"top\">\n                            
                        <a href=\"https://itunes.apple.com/us/podcast/serial/id917918570?mt=2&uo=2\">
                            <img border=\"0\" alt=\"This American Life - Serial  artwork\" src=\"http://is2.mzstatic.com/image/thumb/Podcasts69/v4/90/ef/70/90ef704d-a2d6-ca6f-6972-1b62f8eadb01/mza_7676577196916555630.png/170x170bb-85.jpg\" />
                        </a>\n                        
                    </td>\n                        
                    <td width=\"10\">
                        <img alt=\"\" width=\"10\" height=\"1\" src=\"https://s.mzstatic.com/images/spacer.gif\" />
                    </td>\n                    \t
                    <td width=\"95%\">\n                    \n                    \n                        
                        <b>
                            <a href=\"https://itunes.apple.com/us/podcast/serial/id917918570?mt=2&uo=2\">Serial</a>
                        </b>
                        <br/>\n                        \n                        \n                        \n                        \n\n                        
                        <a href=\"https://itunes.apple.com/us/artist/wbez/id364380278?mt=2&uo=2\">This American Life</a>\n\n                       
                        <font size=\"2\" face=\"Helvetica,Arial,Geneva,Swiss,SunSans-Regular\">\n\t\t\t\t\t\t\n\t\t\t\t\t\t \t
                            <br/>\n                            
                            <b>Genre:</b>
                            <a href=\"https://itunes.apple.com/us/genre/podcasts-news-politics/id1311?mt=2&uo=2\">News & Politics</a>\n                        \n\t\t\t\t\t\t \t
                            <br/>\n                            
                            <b>Release Date:</b> February 6, 2016\n                        \n                        
                        </font>\n                    
                    </td>\n                
                </tr>\n            
            </table>\n        
        </td>\n    
    </tr>\n    
    <tr>\n        
        <td>\n            \n                
            <font size=\"2\" face=\"Helvetica,Arial,Geneva,Swiss,SunSans-Regular\">
                <br/>Serial is a podcast from the creators of This American Life, hosted by Sarah Koenig. Serial unfolds one story - a true story - over the course of a whole season. The show follows the plot and characters wherever they lead, through many surprising twists and turns. Sarah won&#39;t know what happens at the end of the story until she gets there, not long before you get there with her. Each week she&#39;ll bring you the latest chapter, so it&#39;s important to listen in, starting with Episode 1. New episodes are released on Thursday mornings.
            </font>
            <br/>\n            \n            \n            \n                
            <font size=\"2\" face=\"Helvetica,Arial,Geneva,Swiss,SunSans-Regular\"> &#169; © Copyright 2016 Serial Podcast</font>\n\t        \n        
        </td>\n    
    </tr>\n
</table>\n

我只想从这里获取 img src URL。有办法做到这一点吗?

最佳答案

试试这个: console.log($(data.content).find('img').attr('src'));

关于javascript - 从 JSON 对象的 HTML 中解析 img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35247163/

相关文章:

javascript - 如何确定 if::before 应用于元素?

html - 固定标题与下面的内容重叠

HTML/CSS 需要 div 占父级垂直高度的 100%

javascript - Angular 4 应用程序错误 : "core.es5.js:1169 Uncaught Error: No provider for PlatformRef!"

javascript - 通过.js将值传递给php,然后在SQL语句中使用

javascript - 如何使用 or 和条件评估表达式?

javascript - 在文本字段中显示比日期选择器日期晚 3 天的日期

javascript - 递归推送只添加最后一个元素

javascript - 使用 jQuery UI,键盘编辑后无法删除可删除的文本区域

javascript - 将动态加载的 JavaScript 和 CSS 插入页面的最有效方法是什么?