- I am downloading feed using aiohttp asyncio
- Feedparser is supposed to sanitize input text with its _HTMLSanitizer class to accept only specific tags
The sanitizer does not work, any suggestions?
import aiohttpimport asyncioimport feedparserfeedparser._HTMLSanitizer.acceptable_elements = ['a', 'img']feedparser._HTMLSanitizer.acceptable_css_keywords = []feedparser._HTMLSanitizer.acceptable_css_properties = []feedparser._HTMLSanitizer.acceptable_svg_properties = []feedparser._HTMLSanitizer.acceptable_attributes = ['href', 'src']async def load_feed(): async with aiohttp.ClientSession() as session: async with session.get('http://zycrypto.com/feed') as response: text = await response.text() parsed = feedparser.parse(text) for entry in parsed.entries: print(entry.title) print(entry.summary, '\n\n')asyncio.get_event_loop().run_until_complete(load_feed())
Current Output
Pantera Capital CEO: XRP Is One Of The Few Cryptocurrencies That’ll Be Really Important Ten Years From Now<div><img width="696" height="406" src="https://zycrypto.com/wp-content/uploads/2020/08/Pantera-Capital-CEO_-XRP-Is-One-Of-The-Few-Cryptocurrencies-That’ll-Be-Really-Important-Ten-Years-From-Now-1024x597.jpg" class="attachment-large size-large wp-post-image" alt="Pantera Capital CEO: XRP Is One Of The Few Cryptocurrencies That’ll Be Really Important Ten Years From Now" style="margin-bottom: 15px;" srcset="https://zycrypto.com/wp-content/uploads/2020/08/Pantera-Capital-CEO_-XRP-Is-One-Of-The-Few-Cryptocurrencies-That’ll-Be-Really-Important-Ten-Years-From-Now-1024x597.jpg 1024w, https://zycrypto.com/wp-content/uploads/2020/08/Pantera-Capital-CEO_-XRP-Is-One-Of-The-Few-Cryptocurrencies-That’ll-Be-Really-Important-Ten-Years-From-Now-300x175.jpg 300w, https://zycrypto.com/wp-content/uploads/2020/08/Pantera-Capital-CEO_-XRP-Is-One-Of-The-Few-Cryptocurrencies-That’ll-Be-Really-Important-Ten-Years-From-Now-768x448.jpg 768w, https://zycrypto.com/wp-content/uploads/2020/08/Pantera-Capital-CEO_-XRP-Is-One-Of-The-Few-Cryptocurrencies-That’ll-Be-Really-Important-Ten-Years-From-Now.jpg 1200w" sizes="(max-width: 696px) 100vw, 696px" /></div>As we all know, the future is quite unpredictable. The only thing that remains crystal clear is the fact that only the strongest will survive in the long-term. In the crypto space, Ripple’s XRP will be one of the very few cryptocurrencies that will stand the test of time. This is according to Dan Morehead, […] Erik Voorhees: Bitcoin And Stablecoins Will Eventually Take The Place Of Gold And Bank Notes<div><img width="696" height="406" src="https://zycrypto.com/wp-content/uploads/2020/04/Robert-Kiyosaki_-‘Save-Gold-Silver-Bitcoin’-Instead-of-the-Dollar-1024x597.jpg" class="attachment-large size-large wp-post-image" alt="Erik Voorhees: Bitcoin And Stablecoins Will Eventually Take The Place Of Gold And Bank Notes" style="margin-bottom: 15px;" srcset="https://zycrypto.com/wp-content/uploads/2020/04/Robert-Kiyosaki_-‘Save-Gold-Silver-Bitcoin’-Instead-of-the-Dollar-1024x597.jpg 1024w, https://zycrypto.com/wp-content/uploads/2020/04/Robert-Kiyosaki_-‘Save-Gold-Silver-Bitcoin’-Instead-of-the-Dollar-300x175.jpg 300w, https://zycrypto.com/wp-content/uploads/2020/04/Robert-Kiyosaki_-‘Save-Gold-Silver-Bitcoin’-Instead-of-the-Dollar-768x448.jpg 768w, https://zycrypto.com/wp-content/uploads/2020/04/Robert-Kiyosaki_-‘Save-Gold-Silver-Bitcoin’-Instead-of-the-Dollar-610x356.jpg 610w, https://zycrypto.com/wp-content/uploads/2020/04/Robert-Kiyosaki_-‘Save-Gold-Silver-Bitcoin’-Instead-of-the-Dollar.jpg 1200w" sizes="(max-width: 696px) 100vw, 696px" /></div>There have been talks of how Bitcoin could soon take over the financial world in a grand measure, and this idea seems to be winning over more people as time goes. So far, Bitcoin has been proven to be a pretty serious contestant against Gold when it comes to the future of reserve currency. Many […]
None of those other tags have been removed. Can someone please explain what I am doing wrong
Expected output
Contains only HTML with a and img tags and rest of the tags have been removed