Javascript JQuery选择器是否忽略一个元素?

Javascript JQuery选择器是否忽略一个元素?,javascript,jquery,css,jquery-selectors,Javascript,Jquery,Css,Jquery Selectors,我正在提取文章页面内容 一个选择器,“entry”:$('div.content\uuu article-body').html().trim()获取文章主体。 这主要包括带有和标题标记的文本段落,这正是我想要的。 然而,它也有一个我不想要的元素,那就是:“如果你不为它付费,你就是产品。”这就是杂志界正在发生的事情,63年后,免费发行。 这样一来,该书的读者就从顾客转向了广告商。但NME远不是第一家尝试这种伎俩的地产公司,在香港,现在、现在和现在都是放弃自由兑换费用的人。 但皈依者的命运如何?从

我正在提取文章页面内容

一个选择器,
“entry”:$('div.content\uuu article-body').html().trim()
获取文章主体。 这主要包括带有
和标题标记的文本段落,这正是我想要的。 然而,它也有一个我不想要的元素,那就是
:“如果你不为它付费,你就是产品。”这就是杂志界正在发生的事情,63年后,免费发行。

这样一来,该书的读者就从顾客转向了广告商。但NME远不是第一家尝试这种伎俩的地产公司,在香港,现在、现在和现在都是放弃自由兑换费用的人。 但皈依者的命运如何?从那以后,他们的命运告诉了我们和其他运营商什么是成功切换的关键因素

1.了解你的困境 如果说转向免费是出于慈善或市场机会,那就太好了。现实情况是,运营商总是在糟糕的商业前景的外部压力下轻敲开关——再怎么装扮成“大胆重启”也改变不了这一点

NME的发行量正在下降。据知情人士透露,《标准晚报》发现自己在广告策划人的日程安排上远远落后于全国性日报,因而被排除在大品牌广告之外,这让《标准晚报》感到沮丧

《村落之声》被纽约竞争对手的新闻媒体送进了绿色人行道的盒子里,在1996的时候被取消了封面,而香港的标准报纸被迫采取行动,政府取消了上市公司必须在报纸上购买分类广告的法令。但关键——任何听过“寓言”的人都会知道——是认识到什么时候是改变策略的时候了

试试这个


$(“第二部分内容/文章正文*:不(旁注)”)

您可以尝试以下方法:

var e=$('.box').html();
控制台日志(e);
var subStr=e.match((.*);
var r=e.replace(subStr[0],“”);
控制台日志(r)

这里有一些文字
这里有更多的文字

这是一个旁白
使用
.not()
方法,执行如下操作,将选择器扩展到
div.content\uu article-body>*
,使其以
div
的同级为目标,然后循环遍历结果

使用子选择器
>
可以将
中的任何元素排除在一旁
,但这也会影响其他元素,要将其子元素返回到输出中,请使用
.outerHTML

堆栈片段

$('div.content\uuu article-body>*')。不是('aside')。每个(函数(索引,值){
console.log(value.outerHTML);
});

有些段落有些跨度

某个部门 旁白,旁白,旁白
也提供您的HTML,这样我们就知道如何建议正确的答案。在选择器中,您选择的div不是
,这是不正确的。
标记是否位于
div.content\uuu article-body
?使用正则表达式解析HTML是一个很大的禁忌:)。。。对于所请求的方法/选择器有一个正确的用法,我posted@LGSon我又加了一个;)顺便说一句,您的解决方案不会收集变量中的所有内容。。。我想他正在寻找一种方法来提取所有的内容,减去那些不重要的内容。。。在您的情况下,您还可以在侧边中获取内容。因此,最好使用
我想我实际上已经重写了答案,并且感谢您在
旁边写了关于儿童的注释,使用
.not()
可以使用多个参数将其取出。我对儿童选择器的看法是错误的…如何
控制台.log
打印出来看起来所有儿童都走了,但是他们并不是我的第一个问题……因为在这个新问题中,OP想要的东西变得更清楚了:谢谢你的回复。我正在努力实现答案,可能是因为我自己的Javascript熟练程度。我的设置类似于
result={“entry”:$(“jquery\u selector\u here”)}(在
结果中存在多个
“我不确定如何将其与后续的
值.outerHTML
行协调一致。@RobertAndrews您是否可以使用我上面的演示代码手动创建该对象,以便我更好地理解最终结果。例如,在插入时使用一个问题。我不确定console.log的内容是否适合我的应用程序。”用例。@RobertAndrews我想你误解了。我想要一个最终结果的示例,它是根据我在上面的答案中显示的代码示例手动创建的。我想这就是问题所在——我不知道如何去做。你的“not”代码的三行在我插入它们的地方没有完全验证。
$('div.content__article-body').not('aside').html().trim()

$('div.content__article-body').html().not('aside').trim()
</figcaption>
</figure>
</header>
<div class="content__article-body from-content-api js-article__body" itemprop="articleBody" data-test-id="article-review-body">
<p>A wise man once <a href="http://www.quora.com/Who-originally-suggested-that-if-youre-not-paying-for-the-product-you-are-the-product" rel="nofollow" data-link-name="in body link" class="u-underline">said</a>: “If you’re not paying for it, you’re the product.” That’s what is happening in the magazine world, as <a href="https://www.theguardian.com/media/2015/jul/06/nme-to-go-free-with-larger-circulation" data-link-name="in body link" class="u-underline">NME abandons its cover price</a> after 63 years, to go free.<br></p>
<p>In doing so, the title is turning its readers from customers in to advertiser targets. But NME is far from the first property to try this trick. <a href="http://articles.baltimoresun.com/1996-11-13/features/1996318156_1_village-voice-schneiderman-circulation" rel="nofollow" data-link-name="in body link" class="u-underline">The Village Voice</a>, the <a href="http://www.britishpapers.co.uk/england-wmids/shrewsbury-chronicle/" rel="nofollow" data-link-name="in body link" class="u-underline">Shrewsbury Chronicle</a>, the <a href="https://news.google.com/newspapers?id=HU1aAAAAIBAJ&amp;sjid=KSgMAAAAIBAJ&amp;pg=1120%2C535142" rel="nofollow" data-link-name="in body link" class="u-underline">Standard</a> of Hong Kong, <a href="https://gigaom.com/2007/10/31/419-friends-reunited-dropping-subscriptions-to-go-free-ad-supported-report/" rel="nofollow" data-link-name="in body link" class="u-underline">Friends Reunited</a>, the <a href="https://gigaom.com/2009/10/02/419-london-evening-standard-bold-re-birth-or-a-free-folly/" rel="nofollow" data-link-name="in body link" class="u-underline">Evening Standard</a>, the <a href="http://www.fulhamsw6.com/default.asp?section=info&amp;spage=common/contrinity001.htm" rel="nofollow" data-link-name="in body link" class="u-underline">Fulham and Hammersmith Chronicle</a>, Time Out in <a href="https://gigaom.com/2008/09/01/419-time-out-seeking-investors-could-go-free-and-beef-up-online/" rel="nofollow" data-link-name="in body link" class="u-underline">London</a> and <a href="http://www.timeout.com/about/time-out-group/latest-news/time-out-new-york-announces-launch-of-its-magazine-to-free-weekly-distribution" rel="nofollow" data-link-name="in body link" class="u-underline">New York</a>, and now <a href="https://www.theguardian.com/media/greenslade/2015/jul/08/the-sun-lowers-its-paywall-allowing-free-access-to-many-stories" data-link-name="in body link" class="u-underline">parts of the Sun’s website</a> are all among those to have dropped their fees in favour of frees.</p>
<p>But what has become of the converts? And what do their fortunes since tell us, <a href="https://www.theguardian.com/music/nme" data-link-name="auto-linked-tag" data-component="auto-linked-tag" class="u-underline">NME</a> and other operators about the key ingredients for a successful switch?</p>
<aside class="element element-rich-link element--thumbnail element-rich-link--not-upgraded" data-component="rich-link" data-link-name="rich-link-1 | 1">
<div class="rich-link">
<div class="rich-link__container">
<div class="rich-link__header">
<h1 class="rich-link__title">Old media's prospects have improved but the new media threat looms large</h1>
</div>
<div class="rich-link__read-more">
<div class="rich-link__arrow">
<span class="inline-arrow-in-circle inline-icon ">
<svg width="24" height="24" viewbox="0 0 24 24" class="inline-arrow-in-circle__svg inline-icon__svg">
<path class="rich-link__arrow-icon" d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0m.21 19l-.637-.668 4.888-6.326H4.996v-1.01h11.465l-4.888-6.333.637-.668L19 11.153v.685l-6.79 7.157" fill-rule="evenodd"/>
</svg> </span>
</div>
<div class="rich-link__read-more-text">
Read more
</div>
</div>
<a class="rich-link__link u-faux-block-link__overlay" href="https://www.theguardian.com/media-network/2015/mar/20/new-media-threat-buzzfeed-vice" aria-label="Old media's prospects have improved but the new media threat looms large"></a>
</div>
</div>
</aside>
<h2>1. Know your predicament</h2>
<p>It would be nice to say the switch to free comes either out of benevolence or out of a market opportunity. The reality is, operators invariably flick the switch under external pressure of a poor business outlook – no amount of dressing up as a “bold relaunch” can change that.</p>
<p>NME’s circulation was falling by <a href="https://www.theguardian.com/media/2014/feb/13/nme-relaunch-sales-slide-ipc-media" data-link-name="in body link" class="u-underline">around a fifth annually</a>. The Evening Standard was frustrated to find itself far behind national dailies on ad planners’ schedules, locking it out of big brand bucks, according to someone familiar with the strategy to switch.</p>
<p>The Village Voice dropped its cover charge in 1996 after being eaten into by rival New York Press being given away in green sidewalk boxes, while Hong Kong’s Standard newspaper was forced to act when the government removed a decree that listed companies must buy classified ads in newspapers. But the key – as anyone who has heard the “<a href="https://en.wikipedia.org/wiki/Boiling_frog" rel="nofollow" data-link-name="in body link" class="u-underline">boiling frog</a>” allegory will know – is to recognise when it is your time to change tack.</p>