replace special characters in a string python

后端 未结 5 829
感动是毒
感动是毒 2020-12-04 20:06

I am using urllib to get a string of html from a website and need to put each word in the html document into a list.

Here is the code I have so far. I keep getting a

5条回答
  •  抹茶落季
    2020-12-04 20:22

    You can replace the special characters with the desired characters as follows,

    import string
    specialCharacterText = "H#y #@w @re &*)?"
    inCharSet = "!@#$%^&*()[]{};:,./<>?\|`~-=_+\""
    outCharSet = "                               " #corresponding characters in inCharSet to be replaced
    splCharReplaceList = string.maketrans(inCharSet, outCharSet)
    splCharFreeString = specialCharacterText.translate(splCharReplaceList)
    

提交回复
热议问题