Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 01-06-2024, 09:57 AM   #1
Villard
Connoisseur
Villard began at the beginning.
 
Posts: 64
Karma: 10
Join Date: May 2016
Device: Koreader running on Kobo Libra 2
How to remove a 'p' tag with a condition on an inner 'a' tag ?

Hello,
I'm writing a recipe for "The Conservation"
I want to get rid in this below section of all the 2nd 'p' tag with the condition that the'href' attribute in the 'a' tag is equal to "https://theconversation.com/fr/partners".
I've tried several pieces of code, but didn't succed.
Thank you for your help
Villard
<section class="content-partners">
<h3 class="border">Partenaires</h3>
<p class="funding-statement"><a href="https://theconversation.com/institutions/inrae-2182">INRAE</a> apporte des fonds en tant que membre fondateur de The&nbsp;Conversation FR.</p>
<p><a href="https://theconversation.com/fr/partners">Voir les partenaires</a> de The&nbsp;Conversation France</p>
</section>
Villard is offline   Reply With Quote
Old 01-06-2024, 11:11 AM   #2
Villard
Connoisseur
Villard began at the beginning.
 
Posts: 64
Karma: 10
Join Date: May 2016
Device: Koreader running on Kobo Libra 2
I've found this way to solve my question :
for partners in soup.find_all('section', {'class': "content-partners"}):
for partnersTC in partners.find_all('p'):
if 'partners">' in str(partnersTC):
partnersTC.decompose()

I do not use the 'a' tag and its 'href' attribute. Instead I test if the text 'partners">' is present.
There may have a better and proper way to achieve it. Thank you for your input

Villard

Last edited by Villard; 01-06-2024 at 11:18 AM.
Villard is offline   Reply With Quote
Advert
Old 01-07-2024, 08:25 AM   #3
Villard
Connoisseur
Villard began at the beginning.
 
Posts: 64
Karma: 10
Join Date: May 2016
Device: Koreader running on Kobo Libra 2
I finally find a better way
for partners in soup.find_all('section', {'class': "content-partners"}):
for partnersTC in partners.find_all('p'):
for partnersTC2 in partnersTC.find_all ('a',{'href':"https://theconversation.com/fr/partners"}):
partnersTC.decompose()
Villard is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tag Mapper: Remove tag if another specific tag exists? ownedbycats Library Management 2 07-23-2020 10:32 PM
Wondering if there is a way to remove end tag with beginning tag LadyKate Editor 5 06-29-2016 04:32 PM
How to remove this tag? JayKindle Recipes 1 03-24-2012 11:21 AM
Is it possible to remove the 'new' tag? nietsnut Amazon Kindle 9 08-23-2011 11:39 AM
remove tag alexxxm Calibre 1 01-18-2010 04:36 AM


All times are GMT -4. The time now is 12:09 AM.


MobileRead.com is a privately owned, operated and funded community.