Removing new line '\n' from the output of python BeautifulSoup

前端 未结 3 1911
难免孤独
难免孤独 2021-01-12 01:52

I am using python Beautiful soup to get the contents of:

abc def
3条回答
  •  梦毁少年i
    2021-01-12 01:58

    If you just strip items in breadcrum you would end up with empty item in your list. You can either do as shaktimaan suggested and then use

    breadcrum = filter(None, breadcrum)
    

    Or you can strip them all before hand (in html_doc):

    mystring = mystring.replace('\n', ' ').replace('\r', '')
    

    Either way to get your string output, do something like this:

    ','.join(breadcrum)
    

提交回复
热议问题