【发布时间】:2021-02-26 07:43:37
【问题描述】:
我有一个 HTML 源代码。
<div class="placeholderClass">
<h2>THIS IS A PLACEHOLDER</h2> <br>
<p>I want to redirect you to my website over here <a href="https://www.placeholder.com/path/app/stores/HubArticleView?hubId=Hub-100000&placeHoldingID=100000&userID=10000&nameID=40&viewID=10000#parentHorizontalTab2">PLACEHOLDER VIEW</a>.
</p>
</div>
我想从此源获取 href 元素
const $ = cheerio.load(body); // body is the HTML that is loaded above
const IDInfo = {};
const HREF = $('.placeholderClass > h2 > br > p[href])
我正在做最后一行以尝试获取 HREF 链接,因此我无法提取它。
【问题讨论】:
-
您有语法错误,缺少字符串中的右引号。
标签: javascript html jquery jquery-selectors cheerio