Selenium webdriver and unicode

前端 未结 2 1993
心在旅途
心在旅途 2020-12-14 19:19

It\'s my 2nd day with Selenium 2 library and the pain with Unicode never seem to subside.

I\'m just doing the most basic operation, want to print the page source:

相关标签:
2条回答
  • 2020-12-14 19:44

    Instead of print(string), use print(repr(string)) to return a printable representation of the object.

    0 讨论(0)
  • 2020-12-14 19:55

    You have options, based on this similar question.

    You can either convert the source to all ascii losing the Unicode characters in the process.

    (driver.page_source).encode('ascii', 'ignore')

    Or, and I think you'll prefer this, you can encode it to utf-8 like this: (driver.page_source).encode('utf-8').

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