简体   繁体   中英

how to erase text between tags

I'm getting some paragraphs from a web service, but depending of the source url, sometimes I get something like this:

Example 1 : I ask for the text in this online news http://tn.com.ar/sociedad/paso-2017-te-afiliaron-de-prepo-contanos-tu-historia-en-tn-y-la-gente_806433 Then I get the content but the first paragraph I don't need it.

<p> text to erase </p> <--- First 
<p> more text </p>
<p> more text </p>

Example 2 : I ask for the text in this online news http://www.lanacion.com.ar/2044592-ranking-las-15-mejores-propuestas-de-los-portenos-para-mejorar-la-ciudad Then I get the content but the last paragraph I don't need it.

<p> text </p>
<p> more text </p>
<p> text to erase </p> <--- Last

I know what paragraph I need to erase depending the url where I took the text.

I want to how can I erase it. I know that it can be done with a regex, but I don't know nothing about that.

Erasing the text inside first paragraph:

document.querySelector('p:first-child').innerText = ""

Erasing the text inside the last paragraph:

document.querySelector('p:last-child').innerText = ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM