Beautiful Soup Find - get just the text

前端 未结 3 1466
一向
一向 2021-01-22 19:34

I had this bit of code spitting out just the price as a string (125.01), but I must have changed something because now it prints the whole line with the html tags and everything

相关标签:
3条回答
  • You have to call the get_text() method of your price variable:

    print(price.get_text())
    
    0 讨论(0)
  • 2021-01-22 20:08

    You use get_text() on your soup tag.

    print(price.get_text())
    
    0 讨论(0)
  • 2021-01-22 20:15

    Sometimes I've found that .text or .get_text() return an empty string and I have to use:

    print(price.contents[0])

    I think it has to do with unicode vs bytes being returned.

    0 讨论(0)
提交回复
热议问题