Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript从HTML网页提取图像url_Javascript_String_Parsing - Fatal编程技术网

使用javascript从HTML网页提取图像url

使用javascript从HTML网页提取图像url,javascript,string,parsing,Javascript,String,Parsing,我将html节的源代码保存为字符串: var str= '<div class="quizdisplay themestylename theme_db_primarykey"> <h1>What Power Would Suit You Best</h1> <p class="inline_byline"">Created by <a class="url fn" href="/user/xQUANTUMNx

我将html节的源代码保存为字符串:

var str= '<div class="quizdisplay themestylename theme_db_primarykey">
        <h1>What Power Would Suit You Best</h1>
        <p class="inline_byline"">Created by <a class="url fn" href="/user/xQUANTUMNxNOVAx/profile">xQUANTUMNxNOVAx</a></p>

        <div class="metacrumb">

                  <dl>

                    <dt>Tagged:</dt>

                      <dd><a class="tag" rel="tag" href="/tags/dark" title="dark">dark</a></dd>, <dd><a class="tag" rel="tag"
 href="/tags/personality" title="personality">personality</a></dd>,
 <dd><a class="tag" rel="tag" href="/tags/air"
 title="air">air</a></dd>, <dd><a class="tag" rel="tag"
 href="/tags/power" title="power">power</a></dd>, <dd><a class="tag"
 rel="tag" href="/tags/fire" title="fire">fire</a></dd>, <dd><a
 class="tag" rel="tag" href="/tags/water" title="water">water</a></dd>,
 <dd><a class="tag" rel="tag" href="/tags/energy"
 title="energy">energy</a></dd>, <dd><a class="tag" rel="tag"
 href="/tags/earth" title="earth">earth</a></dd>, <dd><a class="tag"
 rel="tag" href="/tags/lightning" title="lightning">lightning</a></dd>,
 <dd><a class="tag" rel="tag" href="/tags/telekinesis"
 title="telekinesis">telekinesis</a></dd>

                   </dl>

                </div>

        <div id="itemresults" class="quidget">
            <p>
                5493 other people got this result!
                That's 34%
            </p>
                        <a class="button viewallresults">View all results</a>
                            <a href="/quizzes" class="button" style="line-height:23px;width:150px;">Take another quiz!</a>

        </div>

        <h3 class="aquestion">Water/Ice.</h3>

                <img src="/user_images/X/XQ/XQU/XQUANTUMNXNOVAX/1346304322_6798_full.jpeg"
 alt="result image" />

        <p>You go with the flow, following the motions of the world around you. You're calming and relaxing but have an aggressive side to
 you when necessary. You can be in tune with people easily, or can be
 completely cold hearted. People typically love you, and need you the
 most.</p>

 </div>';

如何使用javascript从该字符串中提取图像url?

,因为它是HTML。您可以将全部内容插入到DOM隐藏中,并使用jQuery获取图像url,这有点粗糙,但可能是最简单的方法


您还可以使用正则表达式搜索图像标记并从中获取url。

因为它是HTML。您可以将全部内容插入到DOM隐藏中,并使用jQuery获取图像url,这有点粗糙,但可能是最简单的方法

您还可以使用正则表达式搜索图像标记并从中获取url。

jquery 或者您可以使用正则表达式:

var regex = /(?<=<img src=").*?(?=")/gm;
src = regex.match(str);
alert(src);
示例打开。

jquery 或者您可以使用正则表达式:

var regex = /(?<=<img src=").*?(?=")/gm;
src = regex.match(str);
alert(src);

例如。

请从代码和格式属性中删除所有>这不是字符串,这是语法错误我已将整个HTML保存为字符串。请从代码和格式属性中删除所有>这不是字符串,这是一个语法错误。我把整个HTML保存为一个字符串。我需要一个没有任何库的解决方案。我需要一个没有任何库的解决方案。