开发者

Python, Unicode and parsing with lxml and how to deal with 35\xa0new

开发者 https://www.devze.com 2023-04-12 02:42 出处:网络
I am extracting a field on a webpage ad the tag html text content looks like this... 35 new In python the extract开发者_开发技巧ed data looks like this...

I am extracting a field on a webpage ad the tag html text content looks like this...

35 new

In python the extract开发者_开发技巧ed data looks like this...

35\xa0new

How to I deal with unicode in python to convert to a regular string?

"35 new"

what library to I use?

Thanks


Avoid working with regular strings whenever possible; unicodes are generally more useful for text, and there are many well-known solutions for manipulating and dealing with them.


You are getting unicode strings from the parser. You can replace certain characters if you prefer others. For example, your \xa0 is a non-breaking space, and you can replace it with a regular space:

text = text.replace(u"\xa0", u" ")

There could be many of these characters that you want to change, so it might be a long process of finding all the ones that occur in your data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号