Muhammad Danial
Muhammad Danial

Reputation: 168

How to remove "🇺🇸" from a string in python?

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.

Upvotes: 2

Views: 326

Answers (2)

JorgeLuis009
JorgeLuis009

Reputation: 139

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

Upvotes: 2

S. Dave
S. Dave

Reputation: 66

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')

Upvotes: 5

Related Questions