During web scraping and after getting rid of all html tags, I got the black telephone character \u260e in unicode (☎). But unlike this response I do want to get rid of it too.
I used the following regular expressions in Scrapy to eliminate html tags:
pattern = re.compile("<.*?>| |&",re.DOTALL|re.M)
Then I tried to match \u260e and I think I got caught by the backslash plague. I tried unsuccessfully this patterns:
pattern = re.compile("<.*?>| |&|\u260e",re.DOTALL|re.M)
pattern = re.compile("<.*?>| |&|\\u260e",re.DOTALL|re.M)
pattern = re.compile("<.*?>| |&|\\\\u260e",re.DOTALL|re.M)
None of this worked and I still have \u260e as an output. How can I make this disappear?
Using Python 2.7.3, the following works fine for me:
Output:
As pointed by @Zack, this works due to the fact that the string is now in unicode, i.e., the string is already converted, and the sequence of characters
\u260e
is now the -- probably -- two bytes used to write that little black phone ☎ (:Once both the string to be searched and the regular expression have the black phone itself, and not the sequence of characters
\u260e
, they both match.If your string is already unicode, there's two easy ways. The second one will affect more than just the ☎, obviously.
string.printable
You may try with BeatifulSoup, as explained here, with something like