Tuesday, 16 January 2018

Python - HTML to Text for sending SMS - SMS Safe characters - remove \xa0


Following code are some of the alternatives for removing special characters from string:
from bs4 import BeautifulSoup

raw_html = 'Dear Parent,
This is a test message, kindly ignore it. 
Thanks
' clean_text = BeautifulSoup(raw_html, "lxml").text print clean_text #u'Dear Parent,\xa0This is a test message,\xa0kindly ignore it.\xa0Thanks'
The above code produces these characters \xa0 in the string. To remove them properly, we can use two ways. The first one is BeautifulSoup's get_text method with strip argument as True
clean_text = BeautifulSoup(raw_html, "lxml").get_text(strip=True)

print clean_text
# Dear Parent,This is a test message,kindly ignore it.Thanks

The other option is to use python's library unicodedata
import unicodedata

clean_text = BeautifulSoup(raw_html, "lxml").text
print clean_text
#u'Dear Parent,\xa0This is a test message,\xa0kindly ignore it.\xa0Thanks'

new_str = unicodedata.normalize("NFKD",clean_text)
print new_str
# u'Dear Parent,This is a test message,kindly ignore it.Thanks'

65 comments:

  1. I did everything like you wrote, and really, everything works just amazing! So now I can easily send any message to my employees without any extra efforts and nerves. Also I use group texting for business, check over here if you want to learn how do to it too, its very helpful thing for business.

    ReplyDelete
  2. All you have to do is just find a reliable software for sending SMS to thousands of potential customers in time padisoft website

    ReplyDelete
  3. Mobile phones are carried by their users wherever they go, even in the restroom.padisoft.org

    ReplyDelete
  4. You will discover administrations that cover all zones of mystic readings by means of text. It can be an awesome expansion to your entrance to the mystic world.read out loud

    ReplyDelete
  5. You will discover administrations that cover all zones of mystic readings by means of text. It can be an awesome expansion to your entrance to the mystic world.read out loud

    ReplyDelete
  6. I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog, I will keep visiting this blog very often. Receive SMS Online

    ReplyDelete
  7. I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. the best vpn for UK

    ReplyDelete
  8. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info  https://internetprivatsphare.at/vpn-kostenlos/

    ReplyDelete
  9. Whoi, excellent, t wondered just how to cure icne. ind found your webstte by google, dtscovered todiy t'm i ltttle obvtous i greit deil. t’ve ilso idded RSS ind sive your webstte. keep us updited. debestevpn.nl

    ReplyDelete
  10. If you are hiring the developer for a three month contract, at $40.00 per hour, your total cost will be somewhere around $20,000.00. DB Designer

    ReplyDelete
  11. One present why galore businesses opt for postcards is because they are overmuch cheaper to be prefab and this can forbear a lot of expenses on the lengthened run.  vpnveteran

    ReplyDelete
  12. Totally awesome posting! Loads of valuable data and motivation, both of which we all need!Relay welcome your work. Check plagiarism

    ReplyDelete
  13. Text to speech software offers an assortment of advantages, from fundamental criticism when writing to helping visual or learning challenges.notevibes.com

    ReplyDelete
  14. This was a shocking post. It has some look at here fundamental data on this subject. besuche die Website

    ReplyDelete
  15. I'm constantly searching on the internet for posts that will help me. Too much is clearly to learn about this. I believe you created good quality items in Functions also. Keep working, congrats! internetprivatsphare

    ReplyDelete
  16. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on. lemigliorivpn

    ReplyDelete
  17. Reason – First things first; the sole motivation behind Analytics stage is to empower a business to look at its crude information; in all honesty however assessment can help the business in determining some important ends.Data Analytics Course

    ReplyDelete
  18. Are you a web developer? Then give a helping hand to your young ones. Let's grow the world knowledge. Head over to Thinkle Developers and help a seeker please.

    ReplyDelete
  19. The point of this article is to make the assignment of finding a SMS supplier reasonable by offering you a lot of inquiries to pose to yourself before marking with an organization.
    Bulk SMS API

    ReplyDelete
  20. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. dewapoker

    ReplyDelete
  21. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    data analytics courses

    ReplyDelete
  22. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. ExcelR Data Analytics Course Any way I’ll be subscribing to your feed and I hope you post again soon. Big thanks for the use

    ReplyDelete
  23. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.
    data analytics course in Bangalore

    ReplyDelete
  24. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.
    Know more about Data Analytics

    ReplyDelete
  25. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
    Data Science Course

    ReplyDelete
  26. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.

    data science course

    ReplyDelete
  27. Great Content on Python
    Do visit Python Training for the best trainings on Python

    ReplyDelete
  28. I like how this article is written. Your points are sound, original, fresh and interesting. This information has been made so clear there's no way to misunderstand it. Thank you.
    Best Data Science training in Mumbai

    Data Science training in Mumbai

    ReplyDelete
  29. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. Avenue South Residence

    ReplyDelete
  30. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. The Avenir

    ReplyDelete
  31. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. midtown modern condo

    ReplyDelete
  32. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. Clavon Condo

    ReplyDelete
  33. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. myra condo

    ReplyDelete
  34. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. One Pearl Bank

    ReplyDelete
  35. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. Hyll On Holland

    ReplyDelete
  36. Real informative and fantastic anatomical structure of subject material , now that’s user pleasant (:. website designer nyc

    ReplyDelete
  37. A couple of months ago I discovered another website that talked in depth about this topic. I am glad you were able to shed some light on what’s really happening out there. Some webistes are overtly biased towards things like this. Where do you think the industry is going in response to this? website designer nyc

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. F*ckin? tremendous things here. I am very satisfied to see your post. Thank you so much and i’m taking a look forward to contact you. Will you please drop me a mail? branding sf

    ReplyDelete
  40. Call Clavon Showflat Hotline @ +65 6100 9266 / 90261759 for Showflat Appointment, Clavon Showroom Location, Price, Floor plans, E-brochure, VVIP Discount & Site Plans. Clavon Showroom

    ReplyDelete
  41. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  42. Hi there! Good post! Please do tell us when I could see a follow up! ux san francisco

    ReplyDelete
  43. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression

    ReplyDelete
  44. Hi there! Good post! Please do tell us when I could see a follow up!
    text to speech software

    ReplyDelete
  45. PHP and Python are some of the most popular programming languages nowadays. Some of the best free text to speech online with natural voices services were developed using PHP.

    ReplyDelete
  46. the price of insurance quotes would vary from company to company and i always check for the lowest priced insurance quotes,. web design company los angeles

    ReplyDelete
  47. You have a very nice layout for your blog, i want it to use on my site too .     design firms los angeles

    ReplyDelete
  48. ceramic floor tiles are the best, i used to have linoleum tiles but they do not last very long- website design la

    ReplyDelete
  49. Thank you for your very good information and respond to you. san jose car dealers top web design agencies

    ReplyDelete
  50. Thanks for all your efforts that you have put in this. very interesting information. website design company

    ReplyDelete
  51. This comment has been removed by the author.

    ReplyDelete
  52. Previously you must have highly effective web business strategies get you started of getting into topics suitable for their web-based organization. educational web design agency

    ReplyDelete
  53. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  54. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    data science interview questions

    ReplyDelete
  55. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  56. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.

    Simple Linear Regression

    Correlation vs covariance

    KNN Algorithm

    Logistic Regression explained

    ReplyDelete
  57. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Simple Linear Regression
    Correlation vs covariance
    data science interview questions
    KNN Algorithm
    Logistic Regression explained

    ReplyDelete
  58. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Simple Linear Regression
    Correlation vs covariance
    data science interview questions
    KNN Algorithm
    Logistic Regression explained

    ReplyDelete
  59. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    data science interview questions

    ReplyDelete