我有以下来自维基百科主页https://www.wikipedia.org/的HTML代码。 我想要获取href文本。
我尝试过这个
任何建议都非常感激。
//en.wikipedia.org/
<div class="central-featured-lang lang1" lang="en">
<a href="//en.wikipedia.org/" title="English — Wikipedia — The Free Encyclopedia" class="link-box">
<strong>English</strong><br>
<em>The Free Encyclopedia</em><br>
<small>5 077 000+ articles</small>
</a>
</div>
我尝试过这个
$$('.central-featured-lang.lang1 a[href$=".org/"]')
,但我仍然得到整个输出,而不仅仅是href文本。[<a href="//en.wikipedia.org/" title="English — Wikipedia — The Free Encyclopedia" class="link-box">…</a><strong>English</strong><br><em>The Free Encyclopedia</em><br><small>5 077 000+ articles</small></a>]
任何建议都非常感激。
var url = document.querySelector('.central-featured-lang.lang1 a').href;
这会是更好的选择吗? - Ming