2

I'm trying to extract data from facebook but while scraping, I'm stuck at the unicode type error. Actually the text which I'm trying to scrape contains information like:

Hi, this is text

The code which throws an exception of unicodeEncodeError is something like:

driver.find_elements_by_xpath('//p').text

Any hint to overcome this issue.

Håken Lid
  • 22,318
  • 9
  • 52
  • 67

2 Answers2

5

This question is similar to this one: Selenium webdriver and unicode

They recommend converting the whole page to ascii using:

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

You can also encode it to utf-8:

(driver.page_source).encode('utf-8')
S. Dave
  • 66
  • 3
2

Add (driver.page_source).encode('ascii', 'ignore'). That's all you have to do.

Sid S
  • 6,037
  • 2
  • 18
  • 24
JorgeLuis009
  • 139
  • 8
  • Just wondering why people are repeating other peoples' answers. The accepted answer contains the part other answers have written, and it also does not seem to edit to include the same. – Dhruv Singhal Jul 25 '18 at 17:05